Skip to content

Instantly share code, notes, and snippets.

@lamprosg
Created April 21, 2012 09:20
Show Gist options
  • Save lamprosg/2436091 to your computer and use it in GitHub Desktop.
Save lamprosg/2436091 to your computer and use it in GitHub Desktop.
Example: Getting rows from a MySQL table
<?php
$databaseuser="root";
$databasepassword="";
$databasename="eventkicker";
?>
<?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