Jump to content

Why is this returning the same row over and over?


simcoweb

Recommended Posts

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:

[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[/code]

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

Link to comment
Share on other sites

Here's the whole page:

[code]<?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';
?> [/code]
Link to comment
Share on other sites

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:
[code]extract(mysql_fetch_array($result,EXTR_SKIP));[/code]
needs to go inside the while loop like so:
[code]while ($row = mysql_fetch_assoc($result)) {
    extract($row);[/code]
Link to comment
Share on other sites

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.plateauprofessionals.com/display.php
Link to comment
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.