I've got a mysql query that should return a single cell
SELECT `download` FROM `images` WHERE `owner_un`='$owner' AND `url`='$url'
How would I echo the result of this?
Thanks for any help
I've got a mysql query that should return a single cell
SELECT `download` FROM `images` WHERE `owner_un`='$owner' AND `url`='$url'
How would I echo the result of this?
Thanks for any help
There are code snippets in the PHP forum showing you how. Preferably the one using MySQLi or PDO.
In PHP (using mysql), fetching one result:
<?php
$q = "SELECT `download` FROM `images` WHERE `owner_un`='$owner' AND `url`='$url' LIMIT 1";
$rq = mysql_query($q);
$fetch = mysql_fetch_assoc($rq);
echo '<p>Result: ' . $fetch['download'] . '</p>';
Fetching all results:
<?php
$q = "SELECT `download` FROM `images` WHERE `owner_un`='$owner' AND `url`='$url' LIMIT 1";
$rq = mysql_query($q);
while($fetch = mysql_fetch_assoc($rq))
{
echo '<p>Result: ' . $fetch['download'] . '</p>';
}
I second the usage of mysqli/PDO.
pritaeas' code snippets:
http://www.daniweb.com/web-development/php/code/435142/using-phppdo-with-error-checking
http://www.daniweb.com/web-development/php/code/434480/using-phpmysqli-with-error-checking
True, I'd also recommend using PDO/mysqli instead of just mysql :)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.