Jump to content

querys not working?!!?


newb

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
Link to comment
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"
Link to comment
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.
Link to comment
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
Link to comment
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.
Link to comment
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]
Link to comment
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
Link to comment
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..
Link to comment
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
Link to comment
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]

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.