Database query

Started on the old forum in June 2009 · view the original in the archive · old links redirect here

6 replies · 582 views · started 17 years ago · 1 min read

6 participants
synergyx2009 Developer · 86 posts #1

Hi guys

Im trying to call a value or values from a table from a specific row, but for sum reason it aint working, or i got the code wrong.

$item = mysql_fetch_array(mysql_query("SELECT value FROM table WHERE category='a'"));

i want to select all the values in a column called category and print each value and i dont want to use the while statement.

example: i want to print like this: hello  $item[name1]. do you know $item[name2].

|Dont forget to say thanx|

subzero Super moderator Fellow · 3,954 posts #3
$item = mysql_fetch_array(mysql_query("SELECT value,name,car,test FROM table WHERE category='a'"));

$item[0]
$item[1]
$item[2]
$item[3]

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

strikingv Developer · 70 posts #4

can u find a tutorial for sorting data in pages ? SAY like 5 data in 1 page ?

rukiya Lead · 569 posts #5
<?php 
// Connects to your Database 
mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error()); 
mysql_select_db("Database_Name") or die(mysql_error()); 
$data = mysql_query("SELECT * FROM friends LIMIT 5") 
or die(mysql_error()); 
Print "<table border cellpadding=3>"; 
while($info = mysql_fetch_array( $data )) 
{ 
Print "<tr>"; 
Print "<th>Name:</th> <td>".$info['name'] . "</td> "; 
Print "<th>Pet:</th> <td>".$info['pet'] . " </td></tr>"; 
} 
Print "</table>"; 
?>
djdevil89 Senior · 287 posts #6

Did you try

SELECT * FROM table WHERE active='1'

And you also can call it like $item['car'] or whatever your table is

foreach ($_SERVER as $server => $value)
{
echo "$server is $value<br />";
}
anderson Developer · 146 posts #7

try this

synergyx2009 wrote: Hi guys

Im trying to call a value or values from a table from a specific row, but for sum reason it aint working, or i got the code wrong.

$item = mysql_fetch_array(mysql_query("SELECT value FROM table WHERE category='a'"));

i want to select all the values in a column called category and print each value and i dont want to use the while statement.

example: i want to print like this: hello  $item[name1]. do you know $item[name2].

According the code you wrote,,, Try this, if you want to call a specific item:

$item = mysql_fetch_array(mysql_query("SELECT value FROM table WHERE category='a'"));

$that_item = $item[0];

echo "$that_item";

For calling multi items follow the subzero's post. Thanks. @ synergyx2009

Wait...

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close