epicasian Posted January 30, 2010 Share Posted January 30, 2010 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 Quote Link to comment Share on other sites More sharing options...
mapleleaf Posted January 30, 2010 Share Posted January 30, 2010 Are you looking at it locally without php set up on your machine?? Quote Link to comment Share on other sites More sharing options...
Genesis730 Posted January 30, 2010 Share Posted January 30, 2010 What are the names of the rows in your database? Quote Link to comment Share on other sites More sharing options...
teamatomic Posted January 30, 2010 Share Posted January 30, 2010 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 Quote Link to comment Share on other sites More sharing options...
epicasian Posted January 30, 2010 Author Share Posted January 30, 2010 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 Quote Link to comment Share on other sites More sharing options...
teamatomic Posted January 30, 2010 Share Posted January 30, 2010 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 Quote Link to comment Share on other sites More sharing options...
epicasian Posted January 30, 2010 Author Share Posted January 30, 2010 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 Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 30, 2010 Share Posted January 30, 2010 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. Quote Link to comment Share on other sites More sharing options...
epicasian Posted January 30, 2010 Author Share Posted January 30, 2010 after i put all of the info in the separate tables, would i have to include the formatting HTML in the while statement? or is there a shortcut? Thank you again, EpicAsian Quote Link to comment Share on other sites More sharing options...
trq Posted January 30, 2010 Share Posted January 30, 2010 There is no shortcut when that is the logical place for your html. Quote Link to comment Share on other sites More sharing options...
epicasian Posted January 30, 2010 Author Share Posted January 30, 2010 thank you guys for the help. I couldn't think of any other word except shortcut, i just want to get this thing fixed Thank You Again, ~EpicAsian P.S. I'm just beginning PHP if you guess can't tell lol Quote Link to comment Share on other sites More sharing options...
teamatomic Posted January 30, 2010 Share Posted January 30, 2010 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.