...

View Full Version : [php/mysql]



epxine
11-17-2011, 12:19 AM
can someone please tell me whats wrong here


<?php
// Make a MySQL Connection
mysql_connect("localhost", "user", "password") or die(mysql_error());
mysql_select_db("cms") or die(mysql_error());

// Get all the data from the "example" table
$result = mysql_query("SELECT * FROM news ORDER BY id")
or die(mysql_error());

// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table

?>





<div id="post_bg">
<div id="post_txt">
<img src="images/admin_icon.png" width="90px" height="90px" id="post_img">

<a href="#"><?php
echo $row['title'];
}
?></a><br />
<p class="post_text"><font size="-1" face="Times New Roman, Times, serif"><?php
echo $row['content'];
}
?> <br /><br /></p></font>
<label class="post_author"><i>Posted by <a href="#"><?php
echo $row['author'];
}
?></a> <?php
echo $row['date'];
}
?> <a href="#"><?php
echo $row['comments'];
}
?></a></label></i></font>

</div>
</div>



i keep getting syntax error when adding more than 1 echo, i tried only the ['title'] one and it worked but when i started to add content,author,date and comments i get the error.
also the design gets ugly if i add more than 1 news to the database.

Spookster
11-17-2011, 01:11 AM
It probably is because you close the while loop right after you echo the title. Remove the closing brackets } you have added to every one of them and only close the while loop after the last one.

myfayt
11-17-2011, 01:13 AM
The problem is you're using a half dozen closing brackets. Use this code.


<a href="#"><?php
echo $row['title'];

?></a><br />
<p class="post_text"><font size="-1" face="Times New Roman, Times, serif"><?php
echo $row['content'];

?> <br /><br /></p></font>
<label class="post_author"><i>Posted by <a href="#"><?php
echo $row['author'];

?></a> <?php
echo $row['date'];

?> <a href="#"><?php
echo $row['comments'];
}

Spookster beat me to it by seconds!

epxine
11-17-2011, 02:27 AM
The problem is you're using a half dozen closing brackets. Use this code.


<a href="#"><?php
echo $row['title'];

?></a><br />
<p class="post_text"><font size="-1" face="Times New Roman, Times, serif"><?php
echo $row['content'];

?> <br /><br /></p></font>
<label class="post_author"><i>Posted by <a href="#"><?php
echo $row['author'];

?></a> <?php
echo $row['date'];

?> <a href="#"><?php
echo $row['comments'];
}

Spookster beat me to it by seconds!
Thanks both of you!

epxine
11-17-2011, 03:06 PM
how i do to make them only show max 8 topics in that list? so they dont go under the box when theres too many?

s2ooz
11-17-2011, 04:08 PM
how i do to make them only show max 8 topics in that list? so they dont go under the box when theres too many?


$result = mysql_query("SELECT * FROM news ORDER BY id LIMIT 8")

epxine
11-17-2011, 04:52 PM
$result = mysql_query("SELECT * FROM news ORDER BY id LIMIT 8")

Awesome thanks!

also do you know how to make the latest topics in the top? instead of having the first topic_id 1 at the top all time? so it dosn't stays the same if you knw what i mean

myfayt
11-17-2011, 05:06 PM
$result = mysql_query("SELECT * FROM news ORDER BY id DESC LIMIT 8")

or


$result = mysql_query("SELECT * FROM news ORDER BY topic_id DESC LIMIT 8")

epxine
11-17-2011, 05:18 PM
<3 you guys! ty alot



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum