Jump to content

The things I echo in PHP, won't display?


epicasian

Recommended Posts

Hi, I'm trying to make my High School's Newspaper Website easier to maintain by using PHP and a database instead of downloading the site and replacing HTML. I am having a problem with the echo showing up in the body. I created this website in Dreamweaver and Fireworks, so there is A LOT of code...I'm only including the essential stuff...

 

<?php
//connect to db
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("jacketjournal") or die(mysql_error());
//query db
$getnews = mysql_query("SELECT * FROM index_info") or die(mysql_error());
while ($row = mysql_fetch_assoc($getnews))
{
$news_title = $row['news_title'];
$news_byline = $row['news_byline'];
$news_intro = $row['news_intro'];
$news_other_stories = $row['news_other_stories'];

$features_title = $row['features_title'];
$features_byline = $row['features_byline'];
$features_intro = $row['features_intro'];
$features_other_stories = $row['features_other_stories'];

$entertainment_title = $row['entertainment_title'];
$entertainment_byline = $row['entertainment_byline'];
$entertainment_intro = $row['entertainment_intro'];
$entertainment_other_stories = $row['entertainment_other_stories'];

$sports_title = $row['sports_title'];
$sports_byline = $row['sports_byline'];
$sports_intro = $row['sports_intro'];
$sports_other_stories = $row['sports_other_stories'];

}
?>

<td width="200" height="305" valign="top"><p class="style7"><a href="http://jacket-journal.99k.org/hard_news.html" class="style5"><?php  echo "$news_title"; ?><br />
                </a><?php echo "$news_byline"; ?><br><br>
                    <?php echo "$news_intro"; ?><span class="style10"><br />
                    </span><br />

 

NONE of the echos are displaying, can anyone help me?

 

Thank you,

EpicAsian

Link to comment
Share on other sites

You are putting each returned row into an associative array as you go through each row using a while. Yet for your output you do it outside the while. That way you will only get to display the last row, if any at all. You do have more than one row of data dont you? You should put the html/vars/output inside the while. You might also just do a print_r($row) from inside the while to see exactly what you are getting.

 

 

HTH

Teamatomic

Link to comment
Share on other sites

to answer questions:

1.) I have XAMPP installed, so i can see the PHP correctly

2.)In my database, they are named  like :$news_title, without the $

3.)is there any way possible i can call the call the data, without copying the HTML inside the while? b/c i wou;d have to copy and paste the entire while statement many, many times in the same page? and yes, i have multiple pieces of data in the DB

 

Thank you everybody for your help,

EpicAsian

Link to comment
Share on other sites

You are missing part of the gist of how it works. You dont need multiple whiles to get through all the rows. Why would you need multiple html blocks to get all your rows dislayed?

 

while($row...blah){

$var=$row[blah]

echo "$var<br>";

}

 

Will output:

blah

blah

blah

for as many rows as you have

 

an experiment

$i=1;

while($i<=5)

{

echo "$i<br>";

$i++;

}

will output

1

2

3

4

5

 

 

HTH

Teamatomic

Link to comment
Share on other sites

I don't think I'm explaining myself good enough...i need to put the variables in a couple very different places. for example, i need $var1 and $var2 in table 1, $var3 and $var4 in table 2, do you see what I mean? is there any way i can put the values of the vars in the different tables without copying the while statement?

 

 

 

Thank you for you're patience,

EpicAsian

Link to comment
Share on other sites

Based on the code you have posted, you have 4 different categories of information stored in each row, so of course it will be difficult to retrieve the information and use it the way you want on your page.

 

I recommend that you store one article in a row and have a category column that indicates if it is news, feature, entertainment, sports, or any other future category you might add. You should probably also have a DATE (or DATETIME) column to hold a 'published' date (or date/time) so that you can sort and order the information chronologically.

 

Once you do this, you can retrieve any or all of the information in the order that you want, for any choice of category(ies) or for all categories and in any category order and/or by any date order..., for a specific date or date range you want, and in any quantity (only the last x articles...) that you want.

Link to comment
Share on other sites

Ah, I see....said the blind man.

 

No, no short cut. But how long would it take? make one block and then just rename the vars.

Look at heredoc to make it a bit easier and more reqadable.

 

$html= <<<HTML

<td>this is $valid<br>html<p>

inside a <h1>HEREDOC</h1>

its as easy as $cake!

HMTL;

echo $html;

 

 

HTH

Teamatomic

 

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.