Fetch single rows

For an update form I need to fetch singe rows so I created the query like this:

$item_id       = $_GET['item_id'];
$content       = $conn->query("SELECT * FROM menu_kaart_items
						WHERE menu_kaart_item_id = '$item_id'");

To fetch the rows I used:

$row = $content->fetchAll(PDO::FETCH_ASSOC);

But my form fields that look like this:

<input name="menu_item" type="text" class="textfield" value="<?php echo $row->menu_item;?>">

dont return any results.

I used MYSQL before where I used:

$content       = mysql_query("SELECT *
                              FROM menu_kaart_items
			      WHERE menu_kaart_item_id = '$item_id'");
$row = mysql_fetch_object($content);

which gave me the right results but many people here advised me to switch to PDO which I am working on right now but I can’t get my head arround this part.

What am I doing wrong?

Hi donboe, how’s it going?

Calling fetchAll gives you a multidimensional array, even if the query itself only returns a single row. So to access the menu_item column, you’d actually need to do this:

<?php echo $row[0]['menu_item'] ?>

As you only want a single row, use the fetch method instead. In your form code you’re accessing $row as an object, so you’ll also need to specify that you want an object to be returned when you call fetch:

$row = $content->fetch(PDO::FETCH_OBJ);

Hi fretburner. Yes things are nearly quite well :slight_smile: also thanks to you. :tup: Something new learned from your reply. Works great. Can I ask another question it’sabout an update query. Or should I start a new threat?

Sure, yeah. If you wanna start a new thread I’d be happy to take a look :slight_smile:

I will start a new threat then!