Display database rows in html by id

Started by
3 comments, last by future_man 10 years, 8 months ago

Hey, I want to list all of my database entries to a nice html format. For every unique id there is one row displayed out from my database to my php/html. I just don't know how to do that. I tried using while loop and foreach I just don't know how to properly structure them... My query and php code looks like this:


$query = mysql_query("SELECT * FROM sport");

while($row = mysql_fetch_array($query))
{
    $result = $row['sport_ime'].' '.$row['sezona'];
}
Advertisement

Say that your table has 3 columns and you want to list all entries separated by a ',' and break a line after each entry:


$query = "SELECT * FROM sport";
$result = mysql_query($query);
$foundResults = mysql_fetch_array($result);
if(mysql_error())
{
    echo 'Error in query [' . mysql_error() . ']<br>';
}
else if ($foundResults == NULL)
{
    echo 'No results.<br>';
}
else
{
    do
    {
       echo $foundResults[0] . ', ' . $foundResults[1] . ', ' . $foundResults[2] . '<br>';
    } 
    while(($foundResults = mysql_fetch_array($result, MYSQL_NUM)) != NULL);
}

Hope that helps.

may i ask how your using mysql in visual studio?

:)

may i ask how your using mysql in visual studio?

The OP is using PHP and thus most likely isn't using Visual Studio.

The way you'd use MySQL in ASP.Net is quite different from the way you'd use it in C++, even though you can use Visual Studio in both cases so you should probably be a bit more specific.

[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

Say that your table has 3 columns and you want to list all entries separated by a ',' and break a line after each entry:


$query = "SELECT * FROM sport";
$result = mysql_query($query);
$foundResults = mysql_fetch_array($result);
if(mysql_error())
{
    echo 'Error in query [' . mysql_error() . ']<br>';
}
else if ($foundResults == NULL)
{
    echo 'No results.<br>';
}
else
{
    do
    {
       echo $foundResults[0] . ', ' . $foundResults[1] . ', ' . $foundResults[2] . '<br>';
    } 
    while(($foundResults = mysql_fetch_array($result, MYSQL_NUM)) != NULL);
}

Hope that helps.

Thank you, I did a similar approach! Turns out you really need to just put a break tag at the end and echo it :D how simple is that

This topic is closed to new replies.

Advertisement