PDA

View Full Version : PHP - what am I doing wrong?



imagined
March 3rd, 2004, 10:06 AM
Hello! :hr:

I have this:
database:CONTENT
table: HEADING

table HEADING has columns: ID, h1, section, and date_modified.

In table HEADING, column h1, I'm supposed to have headings stored, so I can use them dynamically. This is what I'm trying to achive:

Get the results of:
SELECT h1 FROM heading WHERE section = 'super';

and display them. This is the code that I have and doesn't work:

$head = "super";
$select_h = mysql_query("SELECT h1 FROM heading WHERE section = '$head'");
$fetch_row = mysql_fetch_assoc($select_h);
$content = $fetch_row['content'];

if ($content)
{
echo ("$content");
}
else
{
echo ("You sure are stupid.");
}


Since echo("$content"); doesn't work, the code displays "You sure are stupid". Please help, I'm a begginner here. :h:

Thanks in advance,

Leo

hamza84
March 3rd, 2004, 12:00 PM
try this:


if(isset($content)){
echo $content;

else
echo "You're not stupid, its the script!";


I doubt this would make any difference. If this doesnt work, paste your php code.

imagined
March 3rd, 2004, 02:39 PM
It didn't work. This is what I have:

database:CONTENT
table: HEADING

table HEADING has columns: id, h1, date_modified and section.

This is what I do in the command line:

> USE content
> SELECT * FROM heading;

and it returns:

--------------------------------------------------------------
id | h1 | date_modified | section |
-------------------------------------------------------------
1 | Superintendent | 2004-03-02 | super |
--------------------------------------------------------------

if I do this:

> SELECT h1 FROM heading WHERE section = 'super';

it returns:

---------------------------
h1 |
---------------------------
Superintendent |
---------------------------

That result is the one I want it to display in the page. I just want for it to display Superintendent.

This is the code:

$sql = "SELECT * FROM super";
$sql_heading = "SELECT * FROM heading";
$heading = mysql_query($sql_heading, $connection) or die(mysql_error());

$head = "super";
$select_h = mysql_query("SELECT h1 FROM heading WHERE section = '$head'");
$fetch_row = mysql_fetch_assoc($select_h);
$content = $fetch_row['content'];

if (isset($content))
{
echo ("$content");
}
else
{
echo ("The script is stupid.");
}


Thank you very, very much for your help!

:pleased:

hamza84
March 3rd, 2004, 04:07 PM
you should use:

$connect = mysql_connect(servername, username, password);
mysql_select_db("content", $connect);

use it before the sql statements, obviously

imagined
March 3rd, 2004, 04:25 PM
of course. i had already done that.