trq Posted August 5, 2006 Share Posted August 5, 2006 Still your looking at your database around the wrong way. This code will still work same as your above...[code=php:0]<?phpinclude "config.php";//create connection$connection = mysql_connect("$mysql_host", "$mysql_login", "$mysql_pass") or die ("Couldnt connect to the server.");//select databasemysql_select_db("$mysql_database", $connection) or die ("Couldnt select the database. ".mysql_error());$sql = mysql_query("SELECT data FROM `p16_blocks` WHERE id IN (0,1,2) ORDER BY `id` ASC", $connection);// STEP 1// html definitions - format results by rowwhile ($row = mysql_fetch_row($sql)) { $midlink = $row[0]; echo $midlink;}?>[/code]Now do you get it? Quote Link to comment Share on other sites More sharing options...
newb Posted August 5, 2006 Author Share Posted August 5, 2006 ya i see what u mean. i tried implementing the code in a template system i made, but it kinda failed. well, the code worked, but the template repeated itself downward, it made 3 copies of itself going down.[code]<?phpinclude "sources/config.php";//create connection$connection = mysql_connect("$mysql_host", "$mysql_login", "$mysql_pass") or die ("Couldnt connect to the server.");//select databasemysql_select_db("$mysql_database", $connection) or die ("Couldnt select the database. ".mysql_error());$sql = mysql_query("SELECT data FROM `p16_blocks` WHERE id IN (0,1,2) ORDER BY `id` ASC", $connection);// STEP 1// html definitions - format results by rowwhile ($row = mysql_fetch_row($sql)) { $midlink = $row[0]; $footerlink = $row[1]; $copyright = $row[2]; include $tpath."header.php";echo $midlink;include $tpath."structure.php";include $tpath."structure2.php";echo $footerlink;echo $copyright;include $tpath."footer.php";}?>[/code] Quote Link to comment Share on other sites More sharing options...
trq Posted August 5, 2006 Share Posted August 5, 2006 Look. $row[1] and $row[2] hold nothing in your code!!! Quote Link to comment Share on other sites More sharing options...
beamerrox Posted August 5, 2006 Share Posted August 5, 2006 i would suggest using separate queries till you figure it out... Quote Link to comment Share on other sites More sharing options...
newb Posted August 5, 2006 Author Share Posted August 5, 2006 wtf. $row[1] and $row[2] do hold someting. they hold the information stored in the data field just like $row[0] does. its shown right here: http://img205.imageshack.us/img205/7595/tableod4.jpg Quote Link to comment Share on other sites More sharing options...
newb Posted August 6, 2006 Author Share Posted August 6, 2006 any help pls? Quote Link to comment Share on other sites More sharing options...
trq Posted August 6, 2006 Share Posted August 6, 2006 Your not listening. I suggest you go do a tutorial on querying a database in php. $row[1] and $row[2] do NOT hold any data because you have only queried 1 field in you database (the data field), this one filed shows up in $row[0]. Each time you loop through your result you get another record.Hence... as ive shown you, this...[code=php:0]while ($row = mysql_fetch_row($sql)) { $midlink = $row[0]; echo $midlink;}[/code]produces the same output as all your other redundant code. $row[1] is not equivelent to record 1 as it seems you expect. Quote Link to comment Share on other sites More sharing options...
newb Posted August 7, 2006 Author Share Posted August 7, 2006 well wtf, how do i make it equivelent to record 1??? Quote Link to comment Share on other sites More sharing options...
newb Posted August 7, 2006 Author Share Posted August 7, 2006 oh nevermind, i figured it out, i had to do a separate query for all of them like this:[code]<?phprequire "sources/config.php";//create connection$connection = mysql_connect("$mysql_host", "$mysql_login", "$mysql_pass") or die ("Couldnt connect to the server.");//select databasemysql_select_db("$mysql_database", $connection) or die ("Couldnt select the database. ".mysql_error());$sql = mysql_query("SELECT data FROM `p16_blocks` WHERE id IN (0) ORDER BY `id` ASC", $connection);$sql1 = mysql_query("SELECT data FROM `p16_blocks` WHERE id IN (1) ORDER BY `id` ASC", $connection);$sql2 = mysql_query("SELECT data FROM `p16_blocks` WHERE id IN (2) ORDER BY `id` ASC", $connection);$row = mysql_fetch_row($sql); $midlink = $row[0]; $row1 = mysql_fetch_row($sql1); $footerlink = $row1[0]; $row2 = mysql_fetch_row($sql2); $copyright = $row2[0];?>[/code] Quote Link to comment Share on other sites More sharing options...
trq Posted August 7, 2006 Share Posted August 7, 2006 [quote]oh nevermind, i figured it out, i had to do a separate query for all of them like this:[/quote]What? That is a complete waste of resources. The code you had was working fine... you need the loop to retrieve all records.The way you have it setup now your running 3 queries where you only need one. You REALLY need to understand this stuff. 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.