Jump to content

sql database to php


oursler

Recommended Posts

I'm trying to select and print info from my database to a php page. I can't seem to figure this out. Please help.

 

 

 

<?php

$con = mysql_connect("localhost","****","****");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("my_db", $con);

 

$result = mysql_query("SELECT * FROM Events");

 

while($row = mysql_fetch_array($result))

  {

  echo $row['ename'] . $row['date'] . $row['time'];

  echo "<br />";

  }

 

mysql_close($con);

?>

Link to comment
https://forums.phpfreaks.com/topic/171787-sql-database-to-php/
Share on other sites

Try doing

$recCount = mysql_num_rows($result);

 

then in your while loop

 

while ($t < $recCount){
				$column=mysql_result($recResult,$t,column_name);
				$column2=mysql_result($recResult,$t,column_name2);
				$column3=mysql_result($recResult,$t,column_name3);

//echo code


				$t++;				
				}

Link to comment
https://forums.phpfreaks.com/topic/171787-sql-database-to-php/#findComment-906035
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.