sjonni Posted July 26, 2006 Share Posted July 26, 2006 HiI 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? Quote Link to comment https://forums.phpfreaks.com/topic/15713-simple-mysql-query-help/ Share on other sites More sharing options...
king arthur Posted July 26, 2006 Share Posted July 26, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/15713-simple-mysql-query-help/#findComment-64220 Share on other sites More sharing options...
ryanlwh Posted July 26, 2006 Share Posted July 26, 2006 or[code]echo mysql_result($result,0);[/code]either way, you need one more step. Quote Link to comment https://forums.phpfreaks.com/topic/15713-simple-mysql-query-help/#findComment-64234 Share on other sites More sharing options...
sjonni Posted July 26, 2006 Author Share Posted July 26, 2006 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 35maybe there is a better solution to do this than this one? Quote Link to comment https://forums.phpfreaks.com/topic/15713-simple-mysql-query-help/#findComment-64241 Share on other sites More sharing options...
ryanlwh Posted July 26, 2006 Share Posted July 26, 2006 that means your query is probably not correct. add this to your code:[code] $result = mysql_query($sql) or die(mysql_error());[/code]and tell us what error you got.also post your query. Quote Link to comment https://forums.phpfreaks.com/topic/15713-simple-mysql-query-help/#findComment-64247 Share on other sites More sharing options...
sjonni Posted July 26, 2006 Author Share Posted July 26, 2006 Thanx :)I got it to work after adding the error code .. newbie mistake, misspelled the table name! ::) Quote Link to comment https://forums.phpfreaks.com/topic/15713-simple-mysql-query-help/#findComment-64317 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.