Forum Moderators: coopster

Message Too Old, No Replies

Styling database data

i carnt get my head round the layout of my news

         

riggerz29

8:57 pm on Jan 17, 2009 (gmt 0)

10+ Year Member



hi everyone i have made a mysql table with 4 colums one for photo path one for header one for description and the last for id now i have my results displaying ok but i would like them to look similar to this website <snip> now is this using css to display how the news articles look or php im lost lol im very new to php and css please help

[edited by: eelixduppy at 8:58 pm (utc) on Jan. 17, 2009]
[edit reason] removed URL [/edit]

eelixduppy

9:01 pm on Jan 17, 2009 (gmt 0)



PHP and CSS are used for two completely different tasks. CSS styles content on a webpage where PHP is a server-side scripting language used for many things. If you want your output to be 'styled' then you should look into CSS.

Since the URL that you posted isn't allowed here on the boards, would you mind describing in words what it is you would like your data to look like and we'll see if we can't get this working for you. :)

riggerz29

11:06 pm on Jan 17, 2009 (gmt 0)

10+ Year Member



thanks for the reply, i have a news section on my webpage but its not looking how i would like it to, i need my image say in a table or something that i can apply a nice border round it and have my news header to the right of the image in a nice bold text with the news article underneath it, i have my data being displayed but its just very simple i would like it to look like mmauniverse news section or similar my code to pull my data from mysql is as follows

<?php
// Connects to your Database
mysql_connect("localhost", "user", "password") or die(mysql_error()) ;
mysql_select_db("mwzzzcyg_news") or die(mysql_error()) ;

//Retrieves data from MySQL
$data = mysql_query("SELECT * FROM index_news ORDER BY pid DESC") or die(mysql_error());
//Puts it into an array
while($info = mysql_fetch_array( $data ))
{

//Outputs the image and other data
Echo "<img src=http://www.example.com/newsite/News/".$info['photo'] ."> <br>";
Echo "<b></b> ".$info['header'] . "<br> ";
Echo "<b></b> ".$info['description'] . " <br>";
}
?>

mvaz

7:50 pm on Jan 18, 2009 (gmt 0)

10+ Year Member



If you want your data to be in tabular format, try

$data = mysql_query("SELECT * FROM index_news ORDER BY pid DESC") or die(mysql_error());
?>
<table>
<?php
while($info = mysql_fetch_array($data)) {
?>
<tr>
<td><?php echo $info['photo']); ."<br />" ?>
<?php echo $info['header']); ."<br />" ?>
<?php echo $info['description']); ."<br />" ?>
<hr />
</td>
</tr>
<?php
}
?>
</table>

riggerz29

10:56 pm on Jan 18, 2009 (gmt 0)

10+ Year Member



Thanks for the reply ive tried putting my data in tabular format like you said but im not sure if ive done something wrong i keep getting an error: Parse error: syntax error, unexpected ')', expecting ',' or ';' in /home/mwzzzcyg/public_html/newsite/index3.php on line 147

my code now looks like

<?php
// Connects to your Database
mysql_connect("localhost", "user", "password") or die(mysql_error()) ;
mysql_select_db("mwzzzcyg_news") or die(mysql_error()) ;

//Retrieves data from MySQL
$data = mysql_query("SELECT * FROM index_news ORDER BY pid DESC") or die(mysql_error());
?>
<table>
<?php
while($info = mysql_fetch_array($data)) {
?>
<tr>
<td><?php echo $info['photo']); ."<br />" ?>
<?php echo $info['header']); ."<br />" ?>
<?php echo $info['description']); ."<br />" ?>
<hr />
</td>
</tr>
<?php
}
?>
</table>

mvaz

9:42 am on Jan 19, 2009 (gmt 0)

10+ Year Member



The ; on each <td> line should be after the ."<br /> tag. It was my error that I added the "<br />" tag later and forgot to move the semicolon.

td><?php echo $info['photo'] ."<br />"; ?>
<?php echo $info['header'] ."<br />"; ?>
<?php echo $info['description'] ."<br />"; ?>

Also the brackets need to go.

I think this change should resolve your issue. Let us know how it works.

riggerz29

10:12 am on Jan 19, 2009 (gmt 0)

10+ Year Member



Thanks for your help mvaz it is now displaying ok apart from the image isnt an image it is displaying the image path. One more thing i also tried bringing the data up in a recordset which works aswell but it only brings up the image path. excuse my lack of knowledge im very new to this

mvaz

10:58 am on Jan 19, 2009 (gmt 0)

10+ Year Member



You must echo not just the path, but the src as well. Try

echo "<img src = $info['photo'] ."<br />"; >";