PDA

View Full Version : PHP Help!



Luke
30-05-2011, 08:33 PM
Right, not sure how to explain, but litterally:
MYSQL table, news storys:
Website, "tab display", want 3 most recent stories.
I know how to list them, but not how to do it with the tabs, because of the way they're coded.. can anyone help me out?

Here's an idea of what i want, with examples if there was only one


<?php
$query = "SELECT * FROM news where published = '1' ORDER by id DESC LIMIT 3";
$row_news = mysql_fetch_array($query);
?>
<div id="myTabs">
<ul>
<li><a href="#firsttab"></a><? echo $row_news['shortstory']; ?></li>
<li><a href="#secondtab">newsID2</a></li>
<li id="last"><a href="#thirdtab">newsID3 </a></li>
</ul>
<div id="firsttab" class="tab_content">
<div class="rafat">
<img src="<? echo $row_news['image']; ?>" />
<p> <? echo $row_news['shortstory']; ?> </p>
</div>
</div>
<div id="secondtab" class="tab_content">
<div class="rafat">
<img src="newsIMAGE2" />
<p> newsSTORY2 </p>
</div>
</div>
<div id="thirdtab" class="tab_content">
<div class="rafat">
<img src="newsIMAGE3" />
<p> newsSTORY3 </p>
</div>
</div>
</div>

Jack!
30-05-2011, 08:51 PM
Can you link to the site? I might understand what you mean then :P

Luke
30-05-2011, 09:04 PM
http://i.imgur.com/NJHN6.png
there's an image of what it looks like :')

Jack!
30-05-2011, 09:18 PM
so you want the 3 latest news, each one displayed in a separate tab?

Luke
30-05-2011, 09:22 PM
Yeah, that's the one. I've wrote the query, and what the collumns are called in the table in the code

Jack!
31-05-2011, 09:35 AM
Make it so each tab fetches a certain news article from the database, I'm guessing when a new one is added it becomes 1, and 1 is pushed down to 2, etc. why not make it so tab 1 fetches news one, and tab two fetches news two, etc?

Luke
31-05-2011, 10:27 AM
Make it so each tab fetches a certain news article from the database, I'm guessing when a new one is added it becomes 1, and 1 is pushed down to 2, etc. why not make it so tab 1 fetches news one, and tab two fetches news two, etc?

It doesn't: I've coded it so it just auto increments the ID..
is ther anyway to do it, so it just orders by ID decesnding?
or can you even (i'm sure i've seen this somewhere) make it so i run the query, then when defining the tab values, it'd be something like

tab1 : <? echo $row_news['shortstory']; ?>
tab2 : <? echo $row_news + 1 ['shortstory']; ?>
tab 3 : <? echo $row_news + 2 ['shortstory']; ?>

Obviously that's not the correct syntax, but i'm sure i've seen that done before..

Joe!
31-05-2011, 05:37 PM
you could do


for($x = 0; $x < count( $row_news ); $x++ )
{
echo "<div id=\"tab{$x}\" class=\"tab_content\">
<div class=\"rafat\">
<img src=\"{$row_news[$x]['image']}\" />
<p> {$row_news[$x]['shortstory']}</p>
</div>
</div>";
}

or something like that. im tired

Luke
31-05-2011, 08:48 PM
Not sure i can do it like that, because the way the tabs are coded, they don't repeat the same code three times..

Luke
31-05-2011, 09:46 PM
Got it!
Used arrays to dump the results into
+rep to yous two

Want to hide these adverts? Register an account for free!