Jump to content

Archived

This topic is now archived and is closed to further replies.

newb

querys not working?!!?

Recommended Posts

[code]<?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;
?>
[/code]

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

Share this post


Link to post
Share on other sites
[code]<?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;
?>[/code]

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

Share this post


Link to post
Share on other sites
ok this following code works a little bit:
[code]<?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"
?>
[/code]

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

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

Share this post


Link to post
Share on other sites
[code]
// STEP 1
// html definitions - format results by row
$midlink = $row[0];
$footerlink = $row[1];
$copyright = $row[2];
[/code]
this work?

if not,
[code]
echo $midlink;
echo $footerlink;
echo $copyright;
[/code]
may work

Share this post


Link to post
Share on other sites
Numeric indexes are NOT to be surrounded in quotes. So....

[code=php:0]
$midlink = $row["0"];
[/code]

Should really be....

[code=php:0]
$midlink = $row[0];
[/code]

Share this post


Link to post
Share on other sites
rank may say guru, but you are far newer to php than me...

read 2 posts up eh.

Share this post


Link to post
Share on other sites
ok deletion of SELECT id got rid of the unwanted zero, but still the other html blocks arent showing up.

[code]
<?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;
?>
[/code]

im stuck. :s

Share this post


Link to post
Share on other sites
[quote]rank may say guru, but you are far newer to php than me...[/quote]

We posted at the same time smart guy.

Share this post


Link to post
Share on other sites
[quote]but still the other html blocks arent showing up.[/quote]

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

Share this post


Link to post
Share on other sites
uhh, the html data definitely have html code inside them. http://img205.imageshack.us/img205/7595/tableod4.jpg i posted the tables to even prove it. for some reason only one will show up...

Share this post


Link to post
Share on other sites
[quote author=thorpe link=topic=103059.msg410039#msg410039 date=1154760900]
[quote]but still the other html blocks arent showing up.[/quote]

The code your posting produces NO html. Your also only selecting from the [i]data[/i] field in your query.
[/quote]

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.

Share this post


Link to post
Share on other sites
[quote author=thorpe link=topic=103059.msg410041#msg410041 date=1154761079]
Look at your query!!!!
[/quote]

what about it?

Share this post


Link to post
Share on other sites
Ah... sorry. If you want more than one record you need to use a loop. eg;

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

Share this post


Link to post
Share on other sites
[code]
<?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;
}
?>[/code]

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

[code]
<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>
[/code]
thats what generates on the html page now

Share this post


Link to post
Share on other sites
btw i tried while ($row = $row = $row nothing happened

Share this post


Link to post
Share on other sites
'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..

Share this post


Link to post
Share on other sites
[quote]bah, ur code almost works thorpe, except $midlink doesnt show. [/quote]

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

Share this post


Link to post
Share on other sites
[quote author=thorpe link=topic=103059.msg410051#msg410051 date=1154762107]
[quote]bah, ur code almost works thorpe, except $midlink doesnt show. [/quote]

Because (AS IVE SAID!!!) your only selecting one field!
[/quote]

and hows that a problem? i dont get it, which fields should i select :s

Share this post


Link to post
Share on other sites
Which fields do you want? the table you showed us has the fileds [i]id, name, active[/i] and [i]data[/i].

Share this post


Link to post
Share on other sites
yeah i know, the only field that i needed at the moment was the data field, i was planning on utilizing the other fields later on.

Share this post


Link to post
Share on other sites
Well then.... the only $row that will hoild a value is $row[0].

Share this post


Link to post
Share on other sites
ugh, i figured out the problem.
[code]
<?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 = mysql_fetch_row($sql)) {
  $midlink = $row[0];
  $footerlink = $row[1];
  $copyright = $row[2];
 
  echo $midlink;
  echo $footerlink;
  echo $copyright;
}
?>
[/code]

I needed to remove [code]$row = mysql_fetch_row($sql);[/code]. Fix:
[code]
<?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);

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

Share this post


Link to post
Share on other sites

×

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.