Jump to content


Photo

results of select query omit 1 line


  • Please log in to reply
5 replies to this topic

#1 curtis_b

curtis_b
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 27 February 2006 - 06:25 PM

I'll post some code below, but I don't believe that's where the problem lies.

I'm writing an application for our graphic designers to keep track of proofs online.

[a href=\"http://7cpco.com/proofs/overview.php\" target=\"_blank\"]http://7cpco.com/proofs/overview.php[/a]

As you can see on the page there are (currently) 2 catagories - and I will be adding more after I get this problem solved.

Currently there are 2 results in the top catagory (out for proof) and 1 below (require a revision). The problem is, there really should be 3 in the top and 2 below.

The result set I am getting back from mysql is omiting the first line for each query. If I run the identical query (copy and paste) right in phpMyAdmin, I get the correct results, but from my .php web page, each query is skipping one line and returning everything else.

I have checked the page source to make sure this isn't just a CSS formatting issue.

The queries are pretty simple. For the first catagory - out for proof- I have a column in mysql called Response_y_or_n that auto fills in 'n' upon creation and is later replaced with 'y' when the customer fills out the response form. To return a list of all jobs out to proof I am simply looking for all rows with 'n' for that column.

So my query/loop for that catagory is:

//populate a div full of jobs currently out for proof
$query = "SELECT * FROM proofs where Response_y_or_n='n'";

$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
echo '<div id="wrap"><div class="wrapflow">';
echo '<span class="title">Proofs that we are waiting on:</span><br>';

//labeling the columns
echo '<u><span class="invoice_number">Invoice#</span><span class="customer_orgname">Customer/Org</span><span class="description">Description</span><span class="designer_name">Designer</span><span class="response_target_datetime">Approve by</span><span class="customer_email">Contact</span></u><br>';

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

echo '<span class="invoice_number">'.$row['Invoice_Number'].'</span><span class="customer_orgname">'.$row['Customer_OrgName'].'</span><span class="description"> <a href=http://www.7cpco.com/proofs/'.$row['Filename'].'>'.$row['Description'].'</a></span><span class="designer_name">'.$row['Designer_Name'].'</span><span class="response_target_datetime">'.$row['Response_Target_DateTime'].'</span><span class="customer_email"><a href="mailto:'.$row['Customer_Email'].'">'.$row['Customer_Email'].'</span></a><br>';
}
echo '</div></div><br>';

Thanks for your help!

Curt

#2 joecooper

joecooper
  • Members
  • PipPipPip
  • Advanced Member
  • 358 posts

Posted 27 February 2006 - 06:34 PM

i had this exact problem...

remove this line:

$row = mysql_fetch_array($result) or die(mysql_error());

then it will work
Signature:
[/a]
[a href="http://www.planet-so...=1999&lngWId=8" target="_blank"]EzLogin 1.0[/a]
[a href="http://www.essexracers.com" target="_blank"]Essexracers.com[/a]
Msn Messenger: joe@joeyjoe.co.uk

#3 curtis_b

curtis_b
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 27 February 2006 - 07:21 PM

WOW! I do not understand why that is, but you were right.

I don't see any solved button, otherwise I'd mark it.

Thanks Joe!

#4 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 27 February 2006 - 07:49 PM

Glad you're passing along the wisdom joe. :)

#5 joecooper

joecooper
  • Members
  • PipPipPip
  • Advanced Member
  • 358 posts

Posted 28 February 2006 - 02:02 PM

its to do with the while line having the same code... you dont really need it twice. its confusing, but there probally some major reason behind it :P there allways is
Signature:
[/a]
[a href="http://www.planet-so...=1999&lngWId=8" target="_blank"]EzLogin 1.0[/a]
[a href="http://www.essexracers.com" target="_blank"]Essexracers.com[/a]
Msn Messenger: joe@joeyjoe.co.uk

#6 XenoPhage

XenoPhage
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 28 February 2006 - 07:58 PM

The reason the original code does not work is that the first mysql_fetch_array takes the first result and places it into $row. Think of $results as a stack. Whenever you call mysql_fetch_array, you pop the top result off the stack. So, when you enter the while loop, it pops the next result off and the first one is lost since it was never used anywhere.

XenoPhage
--
[a href=\"http://blog.godshell.com\" target=\"_blank\"]XenoPhage[/a]
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Something mysterious is formed, born in the silent void. Waiting alone and unmoving, it is at once still and yet in constant motion. It is the source of all programs. I do not know its name, so I will call it the Tao of Programming.[/quote]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users