Page 1 of 1

View articles script not displaying MySQL data

Posted: Wed Oct 08, 2003 7:35 am
by sergei

Code: Select all

<?php 

$relative_script_path = '.'; 
include("$relative_script_path/config/config.php"); 

mysql_connect($DBHOST,$DBUSER) or die("Connection unsuccessful" . mysql_error());
mysql_select_db($DBASE) or die("Connection to database unsuccessful: " . mysql_error());

$limit = '5'; // How many results should be shown at a time 
$scroll = '10'; // How many elements to the navigation bar are shown at a time 

// Get the total number of rows in a database 
$query1 = mysql_query("SELECT * FROM article_content, article_info WHERE article_info.article_id = article_content.article_id"); 
$numrows = mysql_num_rows($query1); 
// 

if (!isset ($_GET[show])) { 
   $display = 1; // Change to $NUMROWS if DESCENDING order is required 
} else { 
   $display = $_GET[show]; 
} 

// Return results from START to LIMIT 
$start = (($display * $limit) - $limit); 
$query2 = mysql_query("SELECT * FROM article_content, article_info WHERE article_info.article_id = article_content.article_id LIMIT $start,$limit"); 


print("<table cellpadding=2 width="100%" height="100%" cellspacing=0 border=0>");

while ($row = mysql_fetch_array($query2)) {    
	echo "<p>".$row[ROW]."</p>"; // EDIT TO REFLECT YOUR RESULTS 
	
	$article_name = $row['article_name'];
	$issue_number = $row['issue_number'];
	$issue_date = $row['issue_date'];
	$expiry_date = $row['expiry_date'];
	$page_number = $row['page_number'];
	$reference_number = $row['reference_number'];
	
	$intro = nl2br($row['intro']); 					
	$content = nl2br($row["content"]); 	

	echo ("<tr><td>Title:</td><td><b>$article_name</b></td></tr>");
	echo ("<tr><td>Date:</td><td align=left>$issue_date</td></tr>");
	echo ("<tr><td colspan=2>Issue: <i>$issue_number</i><i><Page: </i>$page_number<br /><br />$intro<br /><a $_SERVER[PHP_SELF]?show=$content>Read More...</a></td></tr><tr><td colspan=2><hr class='hrclass'/></td></tr>");	
     
} 

print("</table><br />"); 

$paging = ceil ($numrows / $limit); 

// Display the navigation 
if ($display > 1) { 
   $previous = $display - 1;    
    
   echo("[ <a href="$_SERVER[PHP_SELF]?show=$previous">< Previous</a> | "); 

} 

if ($numrows != $limit) { 
   if ($paging > $scroll) { 
      $first = $_GET[show]; 
      $last = ($scroll - 1) + $_GET[show]; 
   } else { 
      $first = 1; 
      $last = $paging; 
   } 
      if ($last > $paging ) { 
         $first = $paging - ($scroll - 1); 
         $last = $paging; 
   } 
   for ($i = $first;$i <= $last;$i++){ 
      if ($display == $i) { 
         echo "<b>$i</b> "; 
      } else { 
         echo "<a href="$_SERVER[PHP_SELF]?show=$i">$i</a> "; 
      } 
   } 
} 

if ($display < $paging) { 
   $next = $display + 1; 
   echo("| <a href="$_SERVER[PHP_SELF]?show=$next">Next ></a> ] "); 
    
} 
// 
?>

I want to display articles that have been added to a database. The code above doesn't works through the loop but doesn't display any data.

Any ideas ?

Here's the sql shema

Code: Select all

CREATE TABLE Article_Info(
	Article_ID int NOT NULL AUTO_INCREMENT,
	Article_Type varchar(50),
	Issue_Number int(13),
	Issue_Date date,
	Expiry_Date date,
	Page_Number int(8),
	PRIMARY KEY(Article_id),
	UNIQUE KEY(Article_id)
);

CREATE TABLE Article_Content(
	Article_ID int NOT NULL AUTO_INCREMENT,
	Intro text,
	Content text,
	Reference_number int(20),
	Category_ID int(11),
	PRIMARY KEY(Article_ID),
	UNIQUE KEY(Article_ID)
	
);

Posted: Wed Oct 08, 2003 7:39 am
by Nay
I'm thinking it's most probably because of the use of your arrays. Example:

Code: Select all

$_GET[show]; // is WRONG

$_GET['show']; // is RIGHT
Use the ' and ' in the request unless a number or so. See how the script works after that.

-Nay

Posted: Wed Oct 08, 2003 7:57 am
by sergei
Tried it. Still nothing.

Posted: Wed Oct 08, 2003 8:03 am
by Nay
Could you post the script that you've edited please?

-Nay

Posted: Wed Oct 08, 2003 8:07 am
by sergei

Code: Select all

<?php

$relative_script_path = '.'; 
include("$relative_script_path/config/config.php"); 

mysql_connect($DBHOST,$DBUSER) or die("Connection unsuccessful" . mysql_error());
mysql_select_db($DBASE) or die("Connection to database unsuccessful: " . mysql_error());

$limit = '5'; // How many results should be shown at a time 
$scroll = '10'; // How many elements to the navigation bar are shown at a time 

// Get the total number of rows in a database 
$query1 = mysql_query("SELECT * FROM article_content, article_info WHERE article_info.article_id = article_content.article_id"); 
$numrows = mysql_num_rows($query1); 
// 

if (!isset ($_GET['show'])) { 
   $display = 1; // Change to $NUMROWS if DESCENDING order is required 
} else { 
   $display = $_GET['show']; 
} 

// Return results from START to LIMIT 
$start = (($display * $limit) - $limit); 
$query2 = mysql_query("SELECT * FROM article_content, article_info WHERE article_info.article_id = article_content.article_id LIMIT $start,$limit"); 


print("<table cellpadding=2 width="100%" height="100%" cellspacing=0 border=0>");

while ($row = mysql_fetch_array($query2)) {    
	echo "<p>".$row[ROW]."</p>"; // EDIT TO REFLECT YOUR RESULTS 
	
	$article_name = $row["article_name"];
	$issue_number = $row["issue_number"];
	$issue_date = $row["issue_date"];
	$expiry_date = $row["expiry_date"];
	$page_number = $row["page_number"];
	$reference_number = $row["reference_number"];
	
	$intro = nl2br($row["intro"]); 					
	$content = nl2br($row["content"]); 	

	echo ("<tr><td>Title:</td><td><b>$article_name</b></td></tr>");
	echo ("<tr><td>Date:</td><td align=left>$issue_date</td></tr>");
	echo ("<tr><td colspan=2>Issue: <i>$issue_number</i><i><Page: </i>$page_number<br /><br />$intro<br />Read More...</td></tr><tr><td colspan=2><hr class='hrclass'/></td></tr>");	
     
} 

print("</table><br />"); 

$paging = ceil ($numrows / $limit); 

// Display the navigation 
if ($display > 1) { 
   $previous = $display - 1;    
    
   echo("[ <a href="$_SERVER[PHP_SELF]?show=$previous">< Previous</a> | "); 

} 

if ($numrows != $limit) { 
   if ($paging > $scroll) { 
      $first = $_GET['show']; 
      $last = ($scroll - 1) + $_GET['show']; 
   } else { 
      $first = 1; 
      $last = $paging; 
   } 
      if ($last > $paging ) { 
         $first = $paging - ($scroll - 1); 
         $last = $paging; 
   } 
   for ($i = $first;$i <= $last;$i++){ 
      if ($display == $i) { 
         echo "<b>$i</b> "; 
      } else { 
         echo "<a href="$_SERVER[PHP_SELF]?show=$i">$i</a> "; 
      } 
   } 
} 

if ($display < $paging) { 
   $next = $display + 1; 
   echo("| <a href="$_SERVER[PHP_SELF]?show=$next">Next ></a> ] "); 
    
} 
// 

?>

Posted: Wed Oct 08, 2003 10:44 am
by evilMind
Have you run the query from a mysql terminal (or another means of accessing the data in mysql) with numbers replaced for $start and $limit to verify that it is finding data; It might be that you need to adjust your query?

Posted: Wed Oct 08, 2003 10:50 am
by evilMind
sergei wrote:

Code: Select all

$query2 = mysql_query("SELECT * FROM article_content, article_info WHERE article_info.article_id = article_content.article_id LIMIT $start,$limit");

Code: Select all

CREATE TABLE Article_Info(
   Article_ID int NOT NULL AUTO_INCREMENT,
   Article_Type varchar(50),
   Issue_Number int(13),
   Issue_Date date,
   Expiry_Date date,
   Page_Number int(8),
   PRIMARY KEY(Article_id),
   UNIQUE KEY(Article_id)
);

CREATE TABLE Article_Content(
   Article_ID int NOT NULL AUTO_INCREMENT,
   Intro text,
   Content text,
   Reference_number int(20),
   Category_ID int(11),
   PRIMARY KEY(Article_ID),
   UNIQUE KEY(Article_ID)
   
);
Watch your capitialization if you are running a case sensitive os. (ie, Winblows doesn't care about caps...)
try

Code: Select all

$query2 = "SELECT * FROM `Article_Content`,`Article_Info` WHERE `Article_Info`.`Article_ID`=`Article_Content`.`Article_ID` LIMIT $start,$display";

Posted: Thu Oct 09, 2003 2:12 am
by sergei
The query does process when I run the script (in the browser and in SQLyog) but the variables inside the loop aren't displaying the info.

Could this be caused by some problem with syntax ?

Please advise

Posted: Thu Oct 09, 2003 7:37 am
by evilMind
Well, if you can run the query and get results then it could be where you have

Code: Select all

$article_name = $row["article_name"];
   $issue_number = $row["issue_number"];
   $issue_date = $row["issue_date"];
   $expiry_date = $row["expiry_date"];
   $page_number = $row["page_number"];
   $reference_number = $row["reference_number"];

 /* Which might need to be caps */
//   $article_name = $row['article_name'];  Where does this come from? There is no db entry for this
   $issue_number = $row['Issue_Number'];
   $issue_date = $row['Issue_Date'];
   $expiry_date = $row['Expiry_Date'];
   $page_number = $row['Page_Number'];
   $reference_number = $row['Reference_number'];

Posted: Thu Oct 09, 2003 9:19 am
by sergei
Sorry. Added Article_Name to database later. Forgot to update schema

Posted: Thu Oct 09, 2003 9:34 am
by sergei
Thanks.

Capitalize works