Jump to content


Photo

Why is this returning the same row over and over?


  • Please log in to reply
4 replies to this topic

#1 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 26 August 2006 - 04:48 PM

I have about 20 entries in the database. I'm trying to extract them and display one at a time in a display. Here's the code:

mysql_connect($dbhost, $dbuser, $dbpass) or die('No database here, boss');
mysql_select_db($dbname) or die('That database can not be found, boss.');
$sql=("SELECT * FROM members");
$result = mysql_query($sql) or die('Can not find that database today');
// insert extract function
extract(mysql_fetch_array($result,EXTR_SKIP));
while ($row = mysql_fetch_assoc($result)) {
  echo <<<HTML

But here's the display showing just the first entry over and over again: http://www.plateaupr...com/display.php



#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 26 August 2006 - 04:50 PM

not enough code to go on
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 26 August 2006 - 04:52 PM

Here's the whole page:

<?php 
// test to display addbiz results
include 'config.php';
include 'header.php';
mysql_connect($dbhost, $dbuser, $dbpass) or die('No database here, boss');
mysql_select_db($dbname) or die('That database can not be found, boss.');
$sql=("SELECT * FROM members");
$result = mysql_query($sql) or die('Can not find that database today');
// insert extract function
extract(mysql_fetch_array($result,EXTR_SKIP));
while ($row = mysql_fetch_assoc($result)) {
  echo <<<HTML
<div align='center'>
<table border='0' cellpadding='0' style='border-collapse: collapse' width='530'>
<tr><td colspan='2' background='http://www.plateauprofessionals.com/images/top2.gif' width='530' height='35' style='padding: 10px'><h2>$name</h2>
</td>
</tr><tr>
<td height='15' colspan='2'>
</td>
</tr>
<tr>
<td style='padding-left: 10px; padding-right: 10px; padding-top:5px; padding-bottom:5px' width='229' valign='top'>$image</td>
<td style='padding-left: 10px; padding-right: 10px' width='261'>
<div align='center'>
<table border='0' cellpadding='0' style='border-collapse: collapse' width='100%'>
<tr>
<td style='border-left-width: 1px; border-right-style: solid; border-right-width: 1px; border-top: 1px dotted #666633; border-bottom-width: 1px; padding: 4px' width='46%' bgcolor='#E3E1E1'><font class='bodytext'>
<i>• $title</i></td>
</tr><tr>
<td style='border-left-width: 1px; border-right-style: solid; border-right-width: 1px; border-top-width: 1px; border-bottom: 1px dotted #666633; padding: 4px' width='46%' bgcolor='#EFEDED'>
<font class='bodytext'>• $phone</td></tr>
<tr>
<td style='border-left-width: 1px; border-right-style: solid; border-right-width: 1px; border-top-width: 1px; border-bottom: 1px dotted #666633; padding: 4px' width='46%' bgcolor='#E3E1E1'>
<font class='bodytext'>• $email</td>
</tr><tr>
<td style='border-left-width: 1px; border-right-style: solid; border-right-width: 1px; border-top-width: 1px; border-bottom: 1px dotted #666633; padding: 4px' width='46%' bgcolor='#EFEDED'>
• <a class="body" href="$url">Click Here To Visit My Site</a></td>
</tr>
<tr>
<td style='border-left-width: 1px; border-right-style: solid; border-right-width: 1px; border-top-width: 1px; border-bottom: 1px dotted #666633; padding: 4px' width='46%' bgcolor='#E3E1E1'>
• <a class="body" href='contact.php'>Click here to contact $name</a>
</td>
</tr>
</table>
</div>
&nbsp;</td>
</tr>
<tr>
<td style='padding: 10px' colspan='2'>
<font class='bodytext'><b>About My Services</b></td>
</tr>
<tr>
<td style='padding: 10px' colspan='2' class='bodytext' bgcolor='#e9efef' width='500'>$details</td></tr>
<tr><td style='padding: 10px' colspan='2'>
<font class='bodytext'><b>My Specialties</b></td>
</tr>
<tr><td style='padding: 10px' colspan='2' class='bodytext' bgcolor='#edecde' width='500%'>$specialties</td>
<tr>
<td style='padding-left: 0px; padding-right: 0px; padding-top: 4px; padding-bottom: 4px' background='images/bottom.gif' height='37' colspan='2'>
<p align='center' class='bodytext'>You can use our <a class="body" href='search.php'>key word search</a> option also.</td>
</tr>
</table>
</div>
HTML;
}

include 'footer.php';
?>


#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 26 August 2006 - 04:52 PM

I get
Parse error: parse error, unexpected T_VARIABLE, expecting '(' in /home2/wwwplat/public_html/display.php on line 12
When going to the link provided.

Also everything seems to be fine with the code. Prehap this:
extract(mysql_fetch_array($result,EXTR_SKIP));
needs to go inside the while loop like so:
while ($row = mysql_fetch_assoc($result)) {
    extract($row);


#5 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 26 August 2006 - 05:00 PM

Cool. Moving that 'extract' into the 'while' statement produced the results. Now I have to figure out why in the spot where their image is supposed to show up that it's printing the /tmp name for each one.

That display is back up. I just hadn't uploaded the 'fixed' version when you tried.

http://www.plateaupr...com/display.php




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users