Jump to content


Photo

querys not working?!!?


  • Please log in to reply
34 replies to this topic

#1 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 05 August 2006 - 06:18 AM

<?php
include "config.php";

//create connection
$connection = mysql_connect("$mysql_host", "$mysql_login", "$mysql_pass") or die ("Couldnt connect to the server.");
//select database
$db = mysql_select_db("$mysql_database",$connection) or die ("Couldnt select the database. ".mysql_error());

$sql = mysql_query("SELECT id,data FROM `p16_blocks` WHERE ID IN (0,1,2) ORDER BY `id` ASC");
      $row = mysql_fetch_assoc($sql);

// STEP 1
// html definitions - format results by row
$midlink = $row[0];
$footerlink = $row[1];
$copyright = $row[2];

echo $midlink;
echo $footerlink;
echo $copyright;
?>

wtf this query isnt running. not echoing the html data from the mysql table. pls help, my tables look like this: http://img205.images...95/tableod4.jpg

#2 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 05 August 2006 - 06:29 AM

mysql_fetch_row if you want to use numeric index
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#3 beamerrox

beamerrox
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts
  • LocationGrimshaw, Alberta, Canada

Posted 05 August 2006 - 06:36 AM

<?php
include "config.php";

//create connection
$connection = mysql_connect("$mysql_host", "$mysql_login", "$mysql_pass") or die ("Couldnt connect to the server.");
//select database
mysql_select_db("$mysql_database", $connection) or die ("Couldnt select the database. ".mysql_error());

$sql = mysql_query("SELECT id,data FROM `p16_blocks` WHERE ID IN (0,1,2) ORDER BY `id` ASC", $connection);
$row = mysql_fetch_assoc($sql);

// STEP 1
// html definitions - format results by row
$midlink = $row[0];
$footerlink = $row[1];
$copyright = $row[2];

echo $midlink;
echo $footerlink;
echo $copyright;
?>

deletion of the "$db = "
and addition of a ", $connection to the query"

#4 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 05 August 2006 - 06:44 AM

ok this following code works a little bit:
<?php
include "config.php";
//create connection
$connection = mysql_connect("$mysql_host", "$mysql_login", "$mysql_pass") or die ("Couldnt connect to the server.");
//select database
mysql_select_db("$mysql_database", $connection) or die ("Couldnt select the database. ".mysql_error());

$sql = mysql_query("SELECT id,data FROM `p16_blocks` WHERE ID IN (0,1,2) ORDER BY `id` ASC", $connection);
$row = mysql_fetch_row($sql);

// STEP 1
// html definitions - format results by row
$midlink = $row["0"];
$footerlink = $row["1"];
$copyright = $row["2"];

echo "$midlink";
echo "$footerlink";
echo "$copyright"
?>

It generates this in HTML
0<p align='center' class='midheader'><a href='#'>home</a> • <a href='#'>affiliates</a> • <a href='#'>servers</a> • <a href='#'>contact</a></p>

It doesnt generate the rest of the html blocks, just the $midlink and for some reason it generates a 0 as well.

#5 beamerrox

beamerrox
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts
  • LocationGrimshaw, Alberta, Canada

Posted 05 August 2006 - 06:49 AM

// STEP 1
// html definitions - format results by row
$midlink = $row[0];
$footerlink = $row[1];
$copyright = $row[2];
this work?

if not,
echo $midlink;
echo $footerlink;
echo $copyright;
may work

#6 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 05 August 2006 - 06:50 AM

nope. same thing

#7 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 05 August 2006 - 06:50 AM

Numeric indexes are NOT to be surrounded in quotes. So....

$midlink = $row["0"];

Should really be....

$midlink = $row[0];


#8 beamerrox

beamerrox
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts
  • LocationGrimshaw, Alberta, Canada

Posted 05 August 2006 - 06:51 AM

rank may say guru, but you are far newer to php than me...

read 2 posts up eh.

#9 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 05 August 2006 - 06:53 AM

ok deletion of SELECT id got rid of the unwanted zero, but still the other html blocks arent showing up.

<?php
include "config.php";
//create connection
$connection = mysql_connect("$mysql_host", "$mysql_login", "$mysql_pass") or die ("Couldnt connect to the server.");
//select database
mysql_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);
$row = mysql_fetch_row($sql);

// STEP 1
// html definitions - format results by row
$midlink = $row[0];
$footerlink = $row[1];
$copyright = $row[2];

echo $midlink;
echo $footerlink;
echo $copyright;
?>

im stuck. :s

#10 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 05 August 2006 - 06:54 AM

rank may say guru, but you are far newer to php than me...


We posted at the same time smart guy.

#11 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 05 August 2006 - 06:55 AM

but still the other html blocks arent showing up.


The code your posting produces NO html. Your also only selecting from the data field in your query.

#12 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 05 August 2006 - 06:57 AM

uhh, the html data definitely have html code inside them. http://img205.images...95/tableod4.jpg i posted the tables to even prove it. for some reason only one will show up...

#13 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 05 August 2006 - 06:57 AM

Look at your query!!!!

#14 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 05 August 2006 - 06:59 AM

but still the other html blocks arent showing up.


The code your posting produces NO html. Your also only selecting from the data field in your query.


thats the only field i need to select from. at the moment, i just want to grab data from the table and echo it into the page and for some reason, it fails to do that.

#15 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 05 August 2006 - 06:59 AM

Look at your query!!!!


what about it?

#16 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 05 August 2006 - 07:02 AM

Ah... sorry. If you want more than one record you need to use a loop. eg;

while ($row = mysql_fetch_row($sql)) {
  $midlink = $row[0];
  $footerlink = $row[1];
  $copyright = $row[2];
  echo $midlink;
  echo $footerlink;
  echo $copyright;
}


#17 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 05 August 2006 - 07:07 AM

<?php
include "config.php";
//create connection
$connection = mysql_connect("$mysql_host", "$mysql_login", "$mysql_pass") or die ("Couldnt connect to the server.");
//select database
mysql_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);
$row = mysql_fetch_row($sql);

// STEP 1
// html definitions - format results by row
while ($row = $row = mysql_fetch_row($sql)) {
  $midlink = $row[0];
  $footerlink = $row[1];
  $copyright = $row[2];
  
  echo $midlink;
  echo $footerlink;
  echo $copyright;
}
?>

bah, ur code almost works thorpe, except $midlink doesnt show. the other two blocks generate though (footerlink and copyright)

<p align='center'>Home • Affiliates • Servers • Contact • Teams • 	Signup • Resources • Information • Schedule • Results • Forums • Captains<br /><p align='center'>Copyright 2006 © <b>p16draft.net</b>. All Rights Reserved.</p>
thats what generates on the html page now

#18 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 05 August 2006 - 07:08 AM

btw i tried while ($row = $row = $row nothing happened

#19 xec

xec
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 05 August 2006 - 07:12 AM

'thats the only field i need to select from. at the moment, i just want to grab data from the table and echo it into the page and for some reason, it fails to do that.'

------------

boy,  in your you have only selected one field and it will only give result in $row[0]... just add * instead of data, then $row[0],$row[1],$row[2] all will be working..

#20 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 05 August 2006 - 07:15 AM

bah, ur code almost works thorpe, except $midlink doesnt show.


Because (AS IVE SAID!!!) your only selecting one field!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users