Jump to content

  • Log In with Google      Sign In   
  • Create Account

Display database rows in html by id


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 future_man   Members   -  Reputation: 124

Like
0Likes
Like

Posted 25 August 2013 - 02:47 PM

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'];
}


Sponsor:

#2 CJ_COIMBRA   Crossbones+   -  Reputation: 798

Like
1Likes
Like

Posted 25 August 2013 - 05:54 PM

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.


Edited by CJ_COIMBRA, 25 August 2013 - 05:55 PM.


#3 Anddos   Members   -  Reputation: 498

Like
0Likes
Like

Posted 25 August 2013 - 06:02 PM

may i ask how your using mysql in visual studio?


:)

#4 SimonForsman   Crossbones+   -  Reputation: 6108

Like
0Likes
Like

Posted 25 August 2013 - 08:50 PM

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.


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!

#5 future_man   Members   -  Reputation: 124

Like
0Likes
Like

Posted 26 August 2013 - 05:22 AM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS