Reputation: 49
I have problem (i think for you is simple to solve) with PHP and MySQL. I have database, that call "tekst". There is 3 column:
and the site: index.html.
I want to paste code like that <?php echo "$id1"; ?>
into index.html to display a column "treść" assigned to some "id".
Now I do like that:
$w = mysql_fetch_array(mysql_query("SELECT * FROM tekst WHERE id=5"));
echo $w['tresc'];
but when I have many records, it will be troublesome.
How to create MySQL Query to display what i want ? In one page i will have many ID's.
Please help Thanks
Upvotes: 1
Views: 1145
Reputation: 27364
Try using mysql_fetch_row
.
example
mysql_fetch_row(mysql_query("SELECT * FROM tekst WHERE id=1"));
Official Document
Upvotes: 1
Reputation: 243
First of all, you should use PDO or MySQLi as those mysql_ functions are deprecated.
And then, to list all the ids, use a different query:SELECT * FROM tekst
Which will return an array you should iterate.
Upvotes: 0
Reputation: 1765
You can do it like the following
$result = mysql_query("SELECT * FROM tekst");
while ($r = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo $r['tresc'];
}
Upvotes: 0