Created
April 21, 2012 09:20
-
-
Save lamprosg/2436091 to your computer and use it in GitHub Desktop.
Example: Getting rows from a MySQL table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$databaseuser="root"; | |
$databasepassword=""; | |
$databasename="eventkicker"; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); //start the session | |
include("databaseconnection.php"); | |
//Cnnnecting to the database | |
$link = mysql_connect("localhost", $databaseuser, $databasepassword); | |
mysql_select_db($databasename) or die(mysql_error()); | |
//Example getting a single row from the table | |
$result=mysql_query("SELECT * FROM events WHERE eid=$eid"); | |
$row=mysql_fetch_array($result); | |
$id = $row['id']; | |
//Example getting multiple rows from the table | |
$res=mysql_query("SELECT eid FROM user_favorites WHERE id=$id"); | |
$number=mysql_num_rows($res); //Total rows | |
for ($i=0;$i<$number;$i++) | |
{ | |
$eventid=mysql_result($res,$i,"eid"); | |
$description=mysql_result($res,$i,"description"); | |
$publisher=mysql_result($res,$i,"Publisher"); | |
} | |
//Close the link | |
mysql_close($link); | |
//Redirecting | |
header('Location: link.php'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment