Jump to content

simple mysql query help


sjonni

Recommended Posts

Hi

I am totally new to php and MySQL.
Let my try and explain my problem. I know this is REALLY simple, i´m just not there yet ;)

I am working on a site with multiple pages. I want the same content to be on the left and right side of the pages, so I figured the easiest way was to create a MySQL table to handle the contents.
So it would look something like this

|                |                                |                |
| same for all |        main content      | same for all |
|    pages    |                                |    pages    |

The table consists of 2 fields, ID and content.
the problem is, how do I make a command to show a content from a desired ID.

This is the code in which I thought would do it, but no :(

<?php
$sql = "SELECT content from sidebar WHERE id = 1";
$result = mysql_query($sql);
echo $result;?>

can anyone help me with this?
Link to comment
https://forums.phpfreaks.com/topic/15713-simple-mysql-query-help/
Share on other sites

The result from
[code]
$result = mysql_query($sql);
[/code]

is a result [i]resource[/i], not something you can echo. To get the content you want, you need a further step - you need to fetch an array from that resource and then the content is an element in the array.  So:

[code]
$result = mysql_query($sql);
if($row=mysql_fetch_assoc($result))
{
$content = $row["content"];
echo $content;
}
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.