PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
//connect to the database
$dbhost = "";
$db = "";
$dbuser = "";
$dbpass = "";
$link = mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
$connect = mysql_select_db($db, $link) or die(mysql_error());
//query the database
// If you want to Limit your result, just add LIMIT to your query...
$result = mysql_query("SELECT `nome_curso`, `imagem_curso` FROM `cursos` ORDER BY `nome_curso` LIMIT 0,3") or die(mysql_error());
//output the table
echo '<table cellpadding="2" cellspacing="2">';
while($row = mysql_fetch_array($result)){
echo '<tr><td>'.$row["nome_curso"].'</td></tr><tr><td><img src="'.$row["imagem_curso"].'"></td></tr>';
}
echo '</table>';
?>
As I already commented, if you want to limit your result, just add LIMIT to your query.
And do not fill your call-stack with unnecessary echo calls.
egg82 wrote:The reason I echoed more than needed is because it's much easier to read and change. Human readability should come before computer readability
Yes it should.
This is exactly why the code should be split up into MVC.
<?php
$username = "root";
$password = "";
$hostname = "localhost";
$database = "cursos";
$connect = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
mysql_select_db($database,$connect);
$sql_imagem = "SELECT imagem, nome FROM cursos ORDER BY nome ASC";
echo "<table widht = 100% height = 25% border = 1>";
echo "<tr> <td>";
$executa=mysql_query($sql_imagem,$connect);
while($dados=mysql_fetch_array($executa))
{
extract($dados);
echo "<img src = $imagem>";
}
echo " </td> </tr>";
?>
Now i want to limit the number of columns. And other thing, the name has to appear bellow the image. I was thinking about a <br> or the image in one row and the name in other.
PLEASE THIS IS URGENT
Thank You Very Much
Last edited by PF2G on Thu Oct 27, 2011 5:17 pm, edited 1 time in total.
one last thing: be careful where you get your pictures. Some people like to copyright their work, and you could potentially be in the middle of a legal battle.
Another thing too, your URL for the Bass wont work on any other machine than the server the code is being hosted on. You'll need to give it a net-wide reference not a local one.
mikeashfield wrote:Another thing too, your URL for the Bass wont work on any other machine than the server the code is being hosted on. You'll need to give it a net-wide reference not a local one.
Yes, i saw that mistake, when i was testing the code. Stupid error xP
But now i edited the post. If you could help me...
mikeashfield wrote:Another thing too, your URL for the Bass wont work on any other machine than the server the code is being hosted on. You'll need to give it a net-wide reference not a local one.
Yes, i saw that mistake, when i was testing the code. Stupid error xP
But now i edited the post. If you could help me...
So the code that I posted above didn't work? I don't see anything wrong with it?
mikeashfield wrote:Another thing too, your URL for the Bass wont work on any other machine than the server the code is being hosted on. You'll need to give it a net-wide reference not a local one.
Yes, i saw that mistake, when i was testing the code. Stupid error xP
But now i edited the post. If you could help me...
So the code that I posted above didn't work? I don't see anything wrong with it?
The code you posted, the images didn't appear...
No offense, but i would like to move on to the next step. I need this ASAP.