Garcia Posted January 6, 2007 Share Posted January 6, 2007 Lets start off with my code:[code]<?phpinclude_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 Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted January 6, 2007 Share Posted January 6, 2007 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] Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted January 6, 2007 Share Posted January 6, 2007 I am not clear about ur q.s but if u want this at separate pages or not..What about the javascript. Quote Link to comment Share on other sites More sharing options...
marcus Posted January 6, 2007 Share Posted January 6, 2007 Do[code]$rs = @mysql_query($sql,$con) or die(mysql_error());[/code] Quote Link to comment Share on other sites More sharing options...
Garcia Posted January 6, 2007 Author Share Posted January 6, 2007 Here is what I have now [code]<?phpinclude_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 hereprint $row['description'];//Possible HTML hereprint $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? Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted January 6, 2007 Share Posted January 6, 2007 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. Quote Link to comment Share on other sites More sharing options...
Garcia Posted January 6, 2007 Author Share Posted January 6, 2007 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 ? Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted January 6, 2007 Share Posted January 6, 2007 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? Quote Link to comment Share on other sites More sharing options...
Garcia Posted January 6, 2007 Author Share Posted January 6, 2007 Still no success, maybe I am doing it wrong...Here is what I have now.[code]<?phpinclude_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. Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted January 6, 2007 Share Posted January 6, 2007 The $row[1]... inside the while loop isn't doing anything. You're just telling PHP the variable -- not asking it to print or echo.Also, the $row[1] will only print after the second pass ($i starts at 0), $row[2] only after the third. Quote Link to comment Share on other sites More sharing options...
Garcia Posted January 6, 2007 Author Share Posted January 6, 2007 I don't want it to print or echo inside the loop though thats what I want outside the loop... Quote Link to comment Share on other sites More sharing options...
Garcia Posted January 6, 2007 Author Share Posted January 6, 2007 I still don't have this solved tried different things can anyone help please?Regards,Brian Quote Link to comment 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.