Forum Moderators: coopster

Message Too Old, No Replies

Help with mysql / php basics

php mysql record listing

         

cuce

11:21 pm on May 19, 2008 (gmt 0)

10+ Year Member




I am trying to post these directory listings on my site...
I think I am misunderstanding the use of the while loop....
The result I'm getting is just a repeat of the first listing instead of listing each one...
if anyone can show me what I'm doing wrong it would be hugely appreciated. here's my code

<?
include_once($_SERVER['DOCUMENT_ROOT'] ."/assets/includes/sqlconfig.php") ;
$sql = "SELECT * FROM dir WHERE approved='yes' ORDER BY name ASC";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
while ($row = mysql_fetch_array($result)) {
include_once($_SERVER['DOCUMENT_ROOT'] ."/assets/includes/fieldvars.php") ; // my variables that inform the ones below
?>

<p><strong><?php echo $name ?></strong> <?php echo $address ?><br/>
<?php echo $description ?><br/>
<em>phone: <?php echo $phone ?> ¦ tollfree: <?php echo $tollfree ?> ¦ fax: <?php echo $fax ?> <br/>
website: <?php echo $website ?> ¦ email: <?php echo $email ?></em></p>

<?php
};
?>

cuce

11:37 pm on May 19, 2008 (gmt 0)

10+ Year Member



nm got it

<?php
include_once($_SERVER['DOCUMENT_ROOT'] ."/assets/includes/sqlconfig.php") ;
$sql = "SELECT * FROM dir WHERE approved = 'yes' ORDER BY name ASC";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
include($_SERVER['DOCUMENT_ROOT'] ."/assets/includes/fieldvars.php") ;
?>

<p><strong><?php echo $name ?></strong> <?php echo $address ?><br/>
<?php echo $description ?><br/>
<em>phone: <?php echo $phone ?> ¦ tollfree: <?php echo $tollfree ?> ¦ fax: <?php echo $fax ?> <br/>
website: <?php echo $website ?> ¦ email: <?php echo $email ?></em></p>

<?php
};
?>

StoutFiles

11:39 pm on May 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



you have to pass the field into the variable for every pass.

while ($row = mysql_fetch_array($result)) {
$phone = $row['phone']
//assuming phone is the title of your column
}