Jump to content

Query Placement Problems


Garcia

Recommended Posts

Lets start off with my code:

[code]
<?php
include_once('config.php');

//Pull Queries
$sql = 'SELECT title, description, copyright FROM settings';
$rs = @mysql_query($sql, $con);

while ($row = mysql_fetch_assoc($rs) )
{
print( $row['title'].'<br>' );
print( $row['description'].'<br>' );
print( $row['copyright'].'<br>' );
}
?>
[/code]

This is what it prints... http://trueamericanlife.com/support/

Now what I am trying to figure out is how to predefine my values (title, description, and copyright) and put them where it is needed. Such as :
Top of website would be ['title'] and ['description'] and then have my website content, and then have my ['copyright'] at the very bottom but how do I get the values to work out of the while ($row = mysql_fetch_assoc($rs) ) ?

Much help appreciated.

Thanks,
Brian
Link to comment
Share on other sites

hmmm, your link is dead. Maybe this will help?
[code]<?
include_once('config.php');

//Pull Queries
$sql = 'SELECT title, description, copyright FROM settings';
$rs = @mysql_query($sql, $con);
$row = mysql_fetch_assoc($rs);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
<title><? echo $row['title']; ?></title>
<meta http-equiv="Description" content="<? echo $row['description']; ?>" />
.....[/code]
Link to comment
Share on other sites

Here is what I have now
[code]
<?php
include_once('config.php');

$sql = 'SELECT title, description, copyright FROM settings';
$rs = @mysql_query($sql, $con) or die(mysql_error());
$row = mysql_fetch_assoc($rs);


print "<html><head><title>Ticket System</title></head><body>";

print $row['title'];
//Possible HTML here
print $row['description'];
//Possible HTML here
print $row['copyright'];

print "</body></html>";
?>
[/code]

It only brings up one result which is the title, I would guess because I don't have a loop ? How could I create a loop without having all my values under "while ($row = mysql_fetch_assoc($rs) )"?, would I have to create functions to do this?
Link to comment
Share on other sites

If I'm way off, you'll need to rephrase the question.

Here's how I see it. If you want the title inside the <title></title> area -- just write it in there.

[code]<title><? print "<html><head><title>".$row['title']."</title></head><body>"; ?>[/code]

a loop is irrelevant if you are only getting a single line from the database.
Link to comment
Share on other sites

Ok let me see if I could get it more specific.

When I first made the script everything was in:
[code]
while ($row = mysql_fetch_assoc($rs) )
{
print( $row['title'].'<br>' );
print( $row['description'].'<br>' );
print( $row['copyright'].'<br>' );
}
[/code]
And yes everything was defined correctly but outside the while { } I would try $row['description'] but it didn't do anything.

Now that michaellunsford gave me I can defind $row['copyright'] or the other values anywhere, my problem was that I couldn't outside the while { } .

Now with the loop gone it only brings up my first data $row['title'] how would I be able to get a loop through all my values?

I hope you guys understand this time ?
Link to comment
Share on other sites

mysql_fetch_assoc() will overwrite $row each time it loops through. So, no, you can't access the first row of data outside of the loop if there is more than one row returned.

Now, you could do something like this:
[code=php:0]while($row[$i++]=mysql_fetch_assoc($result)); [/code] which would create a multi-dimentional array. Then you could access the specific line you want and it's data like so:
[code=php:0]echo $row[5]['title'];[/code]

make sense?
Link to comment
Share on other sites

Still no success, maybe I am doing it wrong...

Here is what I have now.

[code]
<?php
include_once('config.php');

$sql = 'SELECT title, description, copyright FROM settings';
$rs = @mysql_query($sql, $con) or die(mysql_error());

while ($row[$i++] = mysql_fetch_assoc($rs) )
{
$row[1]['title'].'<br>';
$row[2]['description'].'<br>';
$row[3]['copyright'].'<br>';
}

echo $row[1]['title'];

?>
[/code]

Did I misunderstood you?, and sorry for not grasping what I say and you say I am new to this and never really understood how to do it.
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.