Jump to content
MakeWebGames

News paper layout


Samurai Legend

Recommended Posts

This is how I want my layout to be -

[ATTACH=CONFIG]2225[/ATTACH]

This is what happens when there is no advertisements -

[ATTACH=CONFIG]2226[/ATTACH]

This is what happens when there is 2 or more advertisements -

[ATTACH=CONFIG]2227[/ATTACH]

Code -

<?php
	require('globals.php');

			echo "<h3><u>Newspaper</u></h3>";

if (!isset($_GET['action']))
{
   $_GET['action'] = '';
}
switch($_GET['action'])
{
case 'add':
add();
break;
case 'delete':
delete();
break;
default:
index();
break;
}




function index() {
global $db, $ir, $notl;

$q = $db->query("SELECT `content` FROM `papercontent` LIMIT 1");
$content= $db->fetch_single($q, 0, 0);


echo "<hr width='95%'>
<table width = '95%' cellspacing = '1' class='table'>
<tr>
<td><a href='job.php'>Your Job</a></td>
<td><a href='gym.php'>Local Gym</a></td>
<td><a href='halloffame.php'>Hall Of Fame</a></td>
<td><a href='clancentral.php'>Clans</a></td>
<td><a href='brothel.php'>Brothel</a></td>
</tr>
<tr>
<td><a href='userlist.php'>Local Residents</a></td>
<td><a href='stats.php'>City Stats</a></td>
<td><a href='usersonline.php'>Users Online</a></td>
<td><a href='clanwars.php'>Current Wars</a></td>
<td><a href='estate.php'>Estate</a></td>
</tr></table><hr width='95%'>";

echo "<table width = '95% cellspacing = '1' class='table'>
<tr>
<th colspan = '5'>Player Advertisements | <a href='newspaper.php?action=add'><b>Buy An Advertisement (¥10,000)</b></a>";
if($ir['user_level'] == 2 OR $ir['user_level'] == 3) {
	echo " | <a href=newspaper.php?action=all><b>[DELETE ALL]</b></a></tr>";
} else {
echo "<tr>";
}
	echo "</tr>
	<tr>
<td colspan = '5'>";
echo "<table width = '95%' cellspacing = '1' class = 'table'>";
echo "<marquee direction = 'up' onmouseover = 'this.stop()' onmouseout = 'this.start()' class = 'textbox' scrolldelay = '125' width = '100%'>";
$anpdata = $db->query("SELECT * FROM `news_paper` ORDER BY `npTIME` DESC");
while ($npdata = $db->fetch_row($anpdata)) {
$time = date('F j',$npdata['npTIME']);
	echo "<div class='codetop'><b>Ad By: <a href='viewuser.php?u={$npdata['npADDER']}'><font color = 'white'>" . $notl->username($npdata['npADDER']) . "</font> [{$npdata['npADDER']}]</a> | Added On: {$time}</b>";

if($ir['user_level'] == 2 OR $ir['user_level'] == 3) {
	echo " | <a href=newspaper.php?action=npID&npID={$npdata['npID']}><b>[DELETE]</b></a></div>";
} else {
echo "</div>";
}
echo "<div class='codemain'><b>{$npdata['npTITLE']}</b> - {$npdata['npBODY']}</div></marquee></table>";
}
echo "</marquee></table>";

echo "<hr width = '95%'><table width = '95% cellspacing = '1' class = 'table'>
	<td><h3><u>Game News</u></h3><div style='text-align: left; padding-left: 5px;'>$content</div></td></tr></table><hr width='95%'><a href = 'index.php'>>Go Home</a><hr width='95%'>";
}

 

Can someone please help me out here! Been trying the past few days could not get anything sorted

1359287680_ScreenShot2015-10-27at01_50_14.png.a83c15a7f01f1e97d7891336d900d330.png

389514481_ScreenShot2015-10-27at01_51_11.png.0c3d2588d6a6766b36e852ae489a70a3.png

902032304_ScreenShot2015-10-27at01_50_38.png.b2080422b9d76058c62fe648a5ed932b.png

Link to comment
Share on other sites

Move the Ad By: code out of the while loop

Use a separate database call to make get the ad data.

I move the code outside the while loop which gave me an errors so I used a function to grab the information to fix the error.

It just gave a News Advert with a title of N/A and also the date as January 1st.

The second point I didn't understand...Sorry still a teenage brain

Link to comment
Share on other sites

I move the code outside the while loop which gave me an errors so I used a function to grab the information to fix the error.

It just gave a News Advert with a title of N/A and also the date as January 1st.

The second point I didn't understand...Sorry still a teenage brain

I'm a teenager also, no excuse.

The second point is to query the database to get the information about the ad.

Your problem is here:

$anpdata = $db->query("SELECT * FROM `news_paper` ORDER BY `npTIME` DESC");
   while ($npdata = $db->fetch_row($anpdata)) {
   $time = date('F j',$npdata['npTIME']);
       echo "<div class='codetop'><b>Ad By: <a href='viewuser.php?u={$npdata['npADDER']}'><font color = 'white'>" . $notl->username($npdata['npADDER']) . "</font> [{$npdata['npADDER']}]</a> | Added On: {$time}</b>";

   if($ir['user_level'] == 2 OR $ir['user_level'] == 3) {
       echo " | <a href=newspaper.php?action=npID&npID={$npdata['npID']}><b>[DELETE]</b></a></div>";
   } else {
   echo "</div>";

 

Think about it. What does while(){} do in programming?

It's a loop. It will repeat everything contained within the curly braces ( { } ) until a condition is met.

Your condition in the while loop is this:

while ($npdata = $db->fetch_row($anpdata)) {

What this is saying to PHP is that you want to repeat everything within the curly braces for every row in the database table that meets your query:

$anpdata = $db->query("SELECT * FROM `news_paper` ORDER BY `npTIME` DESC");

In other words for every newspaper article stored in the table.

Within your while loop you have code that creates the ads that appear in the newspaper:

$time = date('F j',$npdata['npTIME']);
       echo "<div class='codetop'><b>Ad By: <a href='viewuser.php?u={$npdata['npADDER']}'><font color = 'white'>" . $notl->username($npdata['npADDER']) . "</font> [{$npdata['npADDER']}]</a> | Added On: {$time}</b>";

   if($ir['user_level'] == 2 OR $ir['user_level'] == 3) {
       echo " | <a href=newspaper.php?action=npID&npID={$npdata['npID']}><b>[DELETE]</b></a></div>";
   } else {
   echo "</div>";

 

So it creates this ad for every article you have in the newspaper.

Hopefully that has helped you understand your own code and therefore given you something to think about to fix your problem.

Unless I've completely misunderstood the problem...

Edited by Coly010
Link to comment
Share on other sites

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.   Paste as plain text instead

  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...