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
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]
Link to comment
Share on other sites

thank you for your replys, but neither of this seems to work :(

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /var/www/netmynd.is/left.php on line 35

maybe there is a better solution to do this than this one?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.