Jump to content

Variable Not Being Echo'd


spedman975

Recommended Posts

Hi,

 

I am building a webcomic site and as such I have developed a database to hold and output the comics. I have the index page of the comic to output the image (with the alt equalling the comic id and title) and display the comic's title and subtitle below (with a next/prev/first/last navigation and such)...

 

It's all working fine but for some reason the subtitle variable wont appear and I have no idea why.

 

Details:

 

MySQL Version - 5.0.24a-standard-log (According to myphpadmin - Sorry, new to all this)

No errors are output, just no subtitle variable

Table Structure:

 

rss_id: int(5) (Primary Key)
id: int(5)
title: varchar(250)
link: varchar(200)
subtitle: text
description: text
pupdate: varchar(35)
image: varchar(300)

 

Most of this is used for my rss feed though (ie. rss_id, link, description, pubdate)

 

The page coding is as follows: (excluding the header and footer stuff)

 

<?php
include 'config.php';
include 'opendb.php';

// how many rows we have in database
$query   = "SELECT COUNT(id) AS numrows FROM comic";
$result  = mysql_query($query) or die('Error, query failed');
$row     = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];

// how many rows to show per page
$rowsPerPage = 1;

// by default we show first page
$pageNum = $maxPage;

// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}

// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;

$query  = "SELECT * FROM comic ORDER BY id LIMIT $offset, $rowsPerPage";
$result = mysql_query($query) or die('Error, query failed');

// print the random numbers
while($row = mysql_fetch_array($result))
{
   echo "<img src='" .$row['image']. "' width='650' height='350' alt='" .$row['id']. " - " .$row['title']. "'>";
   echo "<br><br><b>" .$row['title']. "</b><br>" .$row['subtitle']. "<br>";
}

echo '<br>';

// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);

$self = $_SERVER['PHP_SELF'];

// creating 'previous' and 'next' link
// plus 'first page' and 'last page' link

// print 'previous' link only if we're not
// on page one
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?page=$page\">[Prev]</a> ";

$first = " <a href=\"$self?page=1\">[First Page]</a> ";
} 
else
{
$prev  = ' [Prev] ';       // we're on page one, don't enable 'previous' link
$first = ' [First Page] '; // nor 'first page' link
}

// print 'next' link only if we're not
// on the last page
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?page=$page\">[Next]</a> ";

$last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
} 
else
{
$next = ' [Next] ';      // we're on the last page, don't enable 'next' link
$last = ' [Last Page] '; // nor 'last page' link
}

// print the page navigation link
echo $first . $prev . " Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages " . $next . $last;

include 'closedb.php';
?>

 

Thats the general code for the whole page. The main issue is the output section:

 

{
   echo "<img src='" .$row['image']. "' width='650' height='350' alt='" .$row['id']. " - " .$row['title']. "'>";
   echo "<br><br><b>" .$row['title']. "</b><br>" .$row['subtitle']. "<br>";
}

 

As I said, all works apart from the ".$row['subtitle']." variable which chooses not to appear. So far I've tried separating the subtitle variable into a seperate echo command, tried changing it to a varchar field type (because the other one's like that seem to work)...

 

Sorry if this all seems a little scattered but any help in this situation would be greatly appreciated!! Thanks!

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.