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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I'm a bit new to all this . . .

Status
Not open for further replies.

Dreamboy2k3

Technical User
Apr 12, 2003
3
0
0
GB
Hello there,

I've just started using PHP and MYSQL -

I want to create a news section on the website where the news administrator can log on and update all the records.

I can get PHP to list all of the entries in a Database, but I just want to now get it to print ONE ROW from the database For example


SELECT * FROM news WHERE News_ID = 1

How do I then use PHP to just print this row?

Any help will be gratefully received!!!

 
For example in this way:

$yourdata = "SELECT * FROM news WHERE News_ID = 1";

$query = mysql_query ($yourdata,$link)
or die ( "Can't execute the request $query");

//Change the name of $link according to the one you use for connecting to your database

$valori = mysql_fetch_array ($query);
$yourvar_1= "$valori ["yourfield_1"];
$yourvar_2= "$valori ["yourfield_2"];
...
This way you will retrieve data from the first row only. If you fear that there could be more then one row in your query, you should check the number of rows to be sure.


Gaetano
 
Hi There,

Thanks for your reply - I am still a little confused however...


Would it be too much to ask if you could explain exactly what is happening in this lines, like where the variables come from. Like I said I am new to this, sorry if this is a bit of "dumb" question!!! Thanking you in advance!!


$valori = mysql_fetch_array ($rs);
$yourvar_1= "$valori ["yourfield_1"];
$yourvar_2= "$valori ["yourfield_2"];



 
u can use this, is more newby-friendly:

$grab = mysql_query("SELECT * FROM news WHERE News_ID = 1",$link);

// now assume u'r table has the "ID" "title" "news" "date" fields..
while(list($id,$title,$news,$date) = mysql_fetch_row($grab)) {

now u have vars with each fields contents, do what u want with them, like:

echo &quot;$title ($date) <br> -» $news&quot;;

}

understand ? :p
 
If you only want to fetch a single row, something like
[tt]list($field1, $field2, $field3) = mysql_fetch_row($resultSetHandle);[/tt]
would put field 1 in the result set in [tt]$field1[/tt], field 2 in [tt]$field2[/tt] and field 3 in [tt]$field3[/tt].

It seems to me that you might want to read the manual, available at
//Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top