phpmysqlprocesswire

Retrieve just one column from MySQL query results


I am trying to create a series of links from data pulled from a database.

Here is the query I am running:

<?php
$result = $db->query("SELECT imageurl FROM products WHERE name LIKE '%$id%' OR title LIKE '%$id%' OR category LIKE '%$id%' LIMIT 0, 15");
while($row = $result->fetch_row())
{
echo '<a href="'.print_r($row).'">'.$row.'</a>'.'<br />';
} ?>

The column "imageurl" contains a full URL to an image. Note that I am using ProcessWire CMS, which is where the unique query references come from.

The resulting output returns the correct entries from the database. The search works. However, they are literally a series of lines like this:

Array ( [0] => http://imagesource.net/graphics/product_images/pACE3-8573838t212.jpg ) Array

The word "array" at the end contains a hyperlink, but it does not link to the correct URL.

I'm sure it's an obvious error. Can anyone point out what's wrong?


Solution

  • Try this:

    echo '<a href="'.$row[0].'">'.$row[0].'</a>'.'<br />';