Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting the right Record with php/mysql

Status
Not open for further replies.

BadChough

Programmer
Dec 20, 2007
137
GB
I suppose the problem with using Dreamweaver to write php/mysql for me is that I don't get to know what's going on!
With the help of DW I have managed to display on a webpage various pieces of text from a mysql table. However it is only displaying text from the first record!
I would like to know how I can simply instruct it to look at other records by specifying the number of the Primary Key. The relevant code is, I think:

<?php require_once('../../../Connections/tormented3.php'); ?>
<?php
mysql_select_db($database_tormented3, $tormented3);
$query_rstcool = "SELECT * FROM cell_cont";
$rstcool = mysql_query($query_rstcool, $tormented3) or die(mysql_error());
$row_rstcool = mysql_fetch_assoc($rstcool);
$totalRows_rstcool = mysql_num_rows($rstcool);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" etc etc

and later;

<?php echo $row_rstcool['cel_org']; ?></span> <!-- Insert Title of Organisation -->
<?php if ($row_rstcool['cel_tel']) echo 'tel. ' ; echo $row_rstcool['cel_tel']; ?><br> <!-- Check for, and Insert Tel Number -->

What piece of code can I insert just before this second piece of code to determine which data record is read, please? This does not need to be a variable value as the data will change whilst the Primary Key will remain the same.
I hope I make sense. Thanks for your help.
 
yup. that only works if there's a primary key in the where clause

otherwise you should wrap your mysql_fetch_assoc in a while clause. lots of examples in the php manual.

 
Its only displaying the first record because that's is all your are telling it to retrieve.

Code:
$row_rstcool = mysql_fetch_assoc($rstcool);

mysql_fetch_assoc will retrieve only one record each time you call it. so as jpadie said put it inside a while clause so it goes through all the records.

Code:
[red]while([/red]$row_rstcool = mysql_fetch_assoc($rstcool)[red]){[/red]
echo $row_rstcool['cel_org']; 
[red]}[/red]

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top