Jump to content

Recommended Posts

Hi there!

 

This query :

 

 

PHP Code:

 

 

SELECT img_name FROM $table WHERE email = '$email' AND ok = '1' ORDER BY id DESC LIMIT 0 , 3") or die("&error=Failed !");

 

is supposed to return a 2 element array (as I already know the content of $table satisfying to the query statements)

 

"ok" is a column which content is 1 (valid image) or 0 (invalid image)

there's 3 rows containing the required $email and only two where ok='1'

 

Statement

 

 

 

PHP Code:

 

 

if ( mysql_num_rows($sql) > 0) {

while ($row =mysql_fetch_array ($sql)) {

$array .= $row['img_name']."|";

}

print "&numberOfRows=".mysql_num_rows($sql)."&myArray=".$array;

}

else {

print "&error=No images found.";

}

 

returns a wrong number of rows (3 instead of 2) but a right array !!!???

 

Why?

 

Many thanks for your advices, remarks and suggestions!

Edited by Germaris
Link to comment
https://forums.phpfreaks.com/topic/273197-unexpected-return/
Share on other sites

Thanks PFMaBISmAd and cpd for responding.

 

Actual output is as I wrote:

 

numberOfRows : 3

myArray : two image names (as expected)

 

Fields in my Flash application display the right information about the array and in the expected order : element1|element2|

with no extra space and nothing after the last "|" glyph

 

To "cpd" = I don't understand how useful will be to select the "email" column in the query.

Would you please explain?

 

Best regards to both of you!

Link to comment
https://forums.phpfreaks.com/topic/273197-unexpected-return/#findComment-1405901
Share on other sites

You have 2 conditions in your query which both have to be met for a result to be returned. MySQL won't decide to return something that doesn't match so the short answer is you have rows in your table that meet the criteria. By selecting the email and ok columns you'll prove this and be able to begin working out what rows match the conditions.

 

This isn't a permanent thing, its just to get you to realise what's happening.

Edited by cpd
Link to comment
https://forums.phpfreaks.com/topic/273197-unexpected-return/#findComment-1405902
Share on other sites

Since you didn't provide any of the requested and actual information that we would need to help you, I'm going to guess that the code you posted isn't the actual and complete code that is producing the incorrect results, since it would be impossible for that code to output what you state.

Edited by PFMaBiSmAd
Link to comment
https://forums.phpfreaks.com/topic/273197-unexpected-return/#findComment-1405904
Share on other sites

Grrr...

Some terms in the script are in french, that's why I didn't post everything...

 

Here is the actual and full script for this function excerpt from the general script (2500 lines!!!)

 

<?php
function photo_history_bypaths($courriel)
{
$table = "_files";
$courriel = trim($courriel);
$sql =mysql_query("SELECT img_name FROM $table WHERE email = '$courriel'AND ok = '1' ORDER BY id DESC LIMIT 0 , 3") or die("&erreur=Échec de la requête !");
if ( mysql_num_rows($sql) > 0) {
while ($row =mysql_fetch_array ($sql)) {
$flashstr .= $row['img_name']."|";
}
print "&erreur="."&nombre=".mysql_num_rows($sql)."&liste=".$flashstr;
}
else {
print "&erreur=Pas de photos présentes pour cet utilisateur.";
}
}
?>

 

The script works nice.

My only problem is: Why it outputs a wrong number of rows (3 instead of 2)?

 

I tried the query in phpMyAdmin with known parameter (my actual email) and it outputs two rows with the expected image names.

Edited by Germaris
Link to comment
https://forums.phpfreaks.com/topic/273197-unexpected-return/#findComment-1405909
Share on other sites

As was suggested, try adding the other column names so you can see what the three rows are.

 

 

 

 

I'm curious what it would look like if you changed it to this:

<?php
function photo_history_bypaths($courriel)
{
$table = "_files";
$courriel = trim($courriel);
$sql =mysql_query("SELECT img_name FROM $table WHERE email = '$courriel'AND ok = '1' ORDER BY id DESC LIMIT 0 , 3") or die("&erreur=Échec de la requête !");
if ( mysql_num_rows($sql) > 0) {
	print "&erreur="."&nombre=".mysql_num_rows($sql)."&liste=".$flashstr;
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/273197-unexpected-return/#findComment-1405919
Share on other sites

I'm curious what it would look like if you changed it to this:

<?php
function photo_history_bypaths($courriel)
{
$table = "_files";
$courriel = trim($courriel);
$sql =mysql_query("SELECT img_name FROM $table WHERE email = '$courriel'AND ok = '1' ORDER BY id DESC LIMIT 0 , 3") or die("&erreur=Échec de la requête !");
if ( mysql_num_rows($sql) > 0) {
	print "&erreur="."&nombre=".mysql_num_rows($sql)."&liste=".[b]$flashstr[/b];
}
}
?>

 

It couldn't work because you have first to fetch the result and, foremost, you should define the $flashstr variable...

And even if you define it, this couldn't work that way...

 

Thanks any way for responding!

 

Question remains:

Why the script outputs a wrong number of rows (3 instead of 2)?

Link to comment
https://forums.phpfreaks.com/topic/273197-unexpected-return/#findComment-1405928
Share on other sites

Seriously dude, I'm working with the code you gave us.

You do NOT have to fetch a row before getting the number of rows.

http://us2.php.net/mysql_num_rows

 

I'm suspecting that is messing up your count, the fact that you're trying to do it after using the rows.

 

 

We can't tell you why it's not showing what you expect because you refuse to do ANYTHING we suggest. I'm done.

Link to comment
https://forums.phpfreaks.com/topic/273197-unexpected-return/#findComment-1405932
Share on other sites

That's what I'm suspecting, too. Try this:


<?php
function photo_history_bypaths($courriel)
{
$table = "_files";
$courriel = trim($courriel);
$sql =mysql_query("SELECT img_name FROM $table WHERE email = '$courriel'AND ok = '1' ORDER BY id DESC LIMIT 0 , 3") or die("&erreur=Échec de la requête !");
$rows = mysql_num_rows($sql); //Only call this function once, before using mysql_fetch_array
if ( $rows > 0) {
while ($row =mysql_fetch_array ($sql)) {
$flashstr .= $row['img_name']."|";
}
print "&erreur="."&nombre=".$rows."&liste=".$flashstr;
}
else {
print "&erreur=Pas de photos présentes pour cet utilisateur.";
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/273197-unexpected-return/#findComment-1405934
Share on other sites

Just to echo Jessica's comments. You've done nothing anyone seems to have suggested and given little information about the problem. I've given you a direction to start with and you've not perused it at all... PFMaBiSmAd pointed stuff out and you just pasted more code without any output from your query.

 

See the link in Jessica's signature "How To Ask Questions": read it, understand it, and if you don't like it don't ever expect a good reply.

Link to comment
https://forums.phpfreaks.com/topic/273197-unexpected-return/#findComment-1405956
Share on other sites

05:00AM... Tough to read...

Oh là là... Please, cool it!

Hey, fellows, this isn't a war...

We all are on a forum to exchange our points of view and opinions.

Nothing more, nothing less...

 

To "Jessica":

 

I never stated you must fetch before to get the number of rows.

I stated you must fetch before to get some data for the variable "$flashstr".

Did you give your script a try?

Me too I'm curious to see the output you got.

Despite what you have written, I gave a try to your script.

It didn't work, exactly because of the reason I told you : You didn't define the variable "$flashstr".

 

To "cpd" and "Jessica":

 

As my project (for this function) is at its very beginning, the table contains only a dozen of rows.

I know their content almost by heart...

I'm working on my own server and have full access to my databases and all their tables.

So, it isn't difficult for me to see if the outputs I get are okay or not.

I gave a try to your suggestion to add columns to SELECT and, as I predicted, it didn't change anything.

 

To "PFMaBiSmAd":

 

My first posting contained all which was necessary to determine if the script should work or not.

I worked meanwhile you posted and didn't necessary have the time to post all the verifications I did.

And I also have, like all of you, a familily life. Even at the age of 72.

It didn't mean I was ignoring advices and suggestions from the members partipating to this discussion.

 

To "shlumph":

 

Your script is very well wrote and worked nice.

I gave it a try replacing the sent variables by their actual values.

It comforted me in my opinion that my own script was good.

 

Conclusion:

 

After having the proof that my PHP Script was good, I made a deep investigation of my Flash .fla file.

Debugging shown that Flash had a misinterpretation of the PHP output it received.

The error was in Flash, not in PHP!!!

And the error was due to a human error.

Mea culpa.

 

For who is still interested, look at my PHP Test in action and the script at the end of this post.

You can see the results at:

http://www.notre-annuaire.com/strict/photos.php

 

I want to thank you all very much for your interest and the time you dedicated to my problem

even if I had the sensation some were irritated by my apparent lack of interest for their posts.

 

Best regards.

 

PS: English isn't my native language, please excuse my mistakes.

 

----------------------------------------------------------------------------

 

My Test script as follows:

 

<?php
include "key.php";
$link = mysql_connect( $host ,$user ,$pass);
if (!$link) {
   die("&erreur=Connexion impossible avec le serveur : " . mysql_error());
}
$db_selected = mysql_select_db( $db, $link);
if (!$db_selected) {
   die ($db." inutilisable : " . mysql_error());
}
$table = "_files";
$courriel = "myemailaddress@xxxxxx.com"; // here, of course, my real email address
$sql =mysql_query("SELECT * FROM $table WHERE email = '$courriel'AND ok = '1' ORDER BY id DESC LIMIT 0 , 3") or die("&erreur=Échec de la requête !");
if ( mysql_num_rows($sql) > 0) {
   while ($row =mysql_fetch_array ($sql)) {
       $flashstr .= $row['img_name']."|";
   }
   print "&erreur="."&nombre=".mysql_num_rows($sql)."&liste=".$flashstr;
}
else {
   print "&erreur=Pas de photos présentes pour cet utilisateur.";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/273197-unexpected-return/#findComment-1406061
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.