0

I am trying to grab ad code from my database and echo it on to the page, but for some reason it is not showing up?

$getad = ("SELECT * FROM ads WHERE place='non-mobile' AND who='adbrite' ");

while($rows = mysql_fetch_array($getad))
{
$code = $rows['code'];
}
$ad1 = $code;

later down the page i print it like this.

<?php print $ad1 ?>
NullPoiиteя
  • 56,591
  • 22
  • 125
  • 143
Glenn
  • 1
  • 1
  • 3
  • 1
    There is no mysql_query. Any error? – gd1 Jan 13 '13 at 09:58
  • What error do you got? Please post it. – Mahmoud Gamal Jan 13 '13 at 09:58
  • 1
    OK, I suggest you to enable error reporting – gd1 Jan 13 '13 at 10:02
  • 1
    [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://stackoverflow.com/a/14110189/1723893). – NullPoiиteя Jan 13 '13 at 11:14

1 Answers1

0

I think your problem is that you don't actually execute the query, you just have saved it in a variable ($getad) and then try to do a fetch af an array containing a string as I see it. If I remeber correctly you have to save you query in a variable, as you did, and then type

$getad = "SELECT * FROM ads WHERE place='non-mobile' AND who='adbrite' ";
$q = $db->query($getad);

// generate results:
while ($q->fetchInto($row)) {
    //display or store
}

You should also include checks, for example that this code has extracted at least one row, or that database connection is working, etcetera.

Ende Neu
  • 15,581
  • 5
  • 57
  • 68