This is for a class project in my databases class. I am making an event database and on the index page I want to make a table that joins the 3 tables in my db. right now all the data is on one table but I want to join all the tables. tables(Sports, Concert, and Restaurant)
<?php
include 'database_connector.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
$result=mysqli_query($con, "select *from Sports LIMIT 0, 30");
echo "<table>";
echo "<tr>
<th>Event Type</th>
<th>Team 1</th>
<th>Team 2</th>
<th>Place</th>
<th>Price</th></tr>";
while($row=mysqli_fetch_array($result)){
$event = $row['event'];
$team1 = $row['Team 1'];
$team2 = $row['Team 2'];
$place = $row['Place'];
$price = $row['Price'];
echo "<tr><td>".$event."</td>
<td>".$team1."</td>
<td>".$team2."</td>
<td>".$place."</td>
<td>" '$'.$price."</td></tr>";
}
echo "</table>"
?>
</body>
</html>
I would like to put a dollar sign in the last column to tell the people viewing the website that is what it costs
Related
My DB has 2 tables mp_details (unique id id) and pic_gal (unique ID pic_id).
pic_gal has a field mp_name which recieves
the value of mp_details id in the master admin page when the link to
visit is clicked the result is supposed to be like this
http://localhost/win-bengal/test-mp-details-new.php?id=['id']&mp_name=['mp_name']
e.g.
http://localhost/win-bengal/test-mp-details-new.php?id=1&mp_name=1 it
works fine for the first link but then onwards the problem starts
localhost/win-bengal/test-mp-details-new.php?id=2&mp_name=1
how ever
when this 1 is changed to 2 manualy the desired result is achieved. So
in other words 'mp_name' is returning just the first value. Please
help
This is the first Recordset which pull all the user information
mysql_select_db($database_mp_db, $mp_db);
$query_Recordset1 = "SELECT * FROM mp_details";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $mp_db) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
This is the second Recordset which pulls information about picture
mysql_select_db($database_mp_db, $mp_db);
$query_Recordset2 = "SELECT * FROM pic_gal";
$Recordset2 = mysql_query($query_Recordset2, $mp_db) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
This query is supposed to act as a bridge between the 2 tables where id of table mp_details is equal to mp_name of table pic_gal
$query = "SELECT mp_details.*, pic_gal.* ".
"FROM mp_details, pic_gal ".
"WHERE mp_details.id = pic_gal.mp_name";
$result = mysql_query($query) or die(mysql_error());
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ADMIN HOME</title>
<link href="../css/css-admin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<p> Add Record | upload Image</p>
<table width="75%" border="0" align="center" cellpadding="5" cellspacing="0">
<tr>
<td bgcolor="#A9C8CB"><strong>id</strong></td>
<td bgcolor="#A9C8CB"><strong>Name</strong></td>
<td bgcolor="#A9C8CB"><strong>District</strong></td>
<td bgcolor="#A9C8CB"><strong>Phone</strong></td>
<td bgcolor="#A9C8CB"><strong>Email</strong></td>
<td bgcolor="#A9C8CB"> </td>
<td bgcolor="#A9C8CB"> </td>
<td bgcolor="#A9C8CB"> </td>
<td bgcolor="#A9C8CB"> </td>
</tr>
<?php do { ?>
<tr>
<td><img src="../images/mp_photos/<?php echo $row_Recordset1['id']; ?>.jpg" alt="<?php echo $row_Recordset1['name']; ?>" width="" height="" border="0" title="<?php echo $row_Recordset1['name']; ?>" /><br /><?php echo $row_Recordset1['name']; ?></td>
</body>
</html>
<?php
mysql_free_result($Recordset1);
mysql_free_result($Recordset2);
?>
here
< ? php echo $row_Recordset2['mp_name']; ? >
is supposed to echo the same value ad 'id' but it isn't happening so. it only echos the first value
So I was importing some MySQL Rows into a form but there seems to be an issue, the database doesnot connects, it says no database selected, I have my Database connection parameters in constants.php and they are working fine in the other pages of the website, and there is no syntax error in the commands either, Help me please.Thanks!
<?php
require_once 'classes/Membership.php';
require_once 'includes/constants.php';
$membership = New Membership();
$membership->confirm_Member();
$con = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or
die('Error connecting Database');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
<title>Post Scores | Admin Panel D2C</title>
<style type="text/css">
</style>
</head>
<body>
<div class="main_body">
<table width="1029" border="0" cellpadding="0" class="score_table" >
<td width="131">
<form align="center" action="update_team_database.php" method="post">
<tr>
<td> Team: </td>
<td width="831">
<?php
$result = mysql_query("select DISTINCT TeamName from team") or die(mysql_error());
echo '<select name="teamname1"><OPTION>';
echo "Select a team</OPTION>";
while ($row = mysql_fetch_array($result)){
$team1 = $row["TeamName"];
echo "<OPTION value=\"$team1\">$team1</OPTION>";
}
echo '</SELECT>';
?></td>
</tr>
</form>
</table>
</body>
</html>
I would recommend you make use of Object Oriented way of performing queries over MySQL using MySQLi
You may check the example in here
http://in2.php.net/manual/en/mysqli.query.php
Since MySQL is deprecated as of PHP 5.5
Hi i've managed to make some sort of a comment box that relies on the use of a mysql database and php coding. I'm able to run the comment box by opening its index.php file on my server but when i try adding it to a html page by using a simple include_once php code
it doesn't seem to work.
please excuse me if I sound stupid but this is my first time using php.
here is the code i've been trying to use.
<?php
include_once("../connect.php");
$commenting_form = '<form action="addcomment.php" method="post">
<table width="310" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><strong>Add Comment:</strong></td>
</tr>
<tr>
<td width="105">Title</td>
<td width="205"><input type="text" name="msg_title" id="msg_title" style="width:200px;" /></td>
</tr>
<tr>
<td colspan="2"><textarea name="msg_message" id="msg_message" style="width:100%;height:200px;font-family:Courier New">Message</textarea></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Add Comment" name="msg_submit" id="msg_submit" /></td>
</tr>
</table>
</form>';
$get_comments = mysql_query("SELECT * FROM comments");
$comments_count = mysql_num_rows($get_comments);
if ($comments_count>0)
{
while ($com = mysql_fetch_array($get_comments))
{
$id = $com['id'];
$title = $com['text'];
$message = $com['message'];
$comment .= '<strong>'.$title.'</strong><br />'.$message.'<hr />';
}
$comment .= $commenting_form;
$page_title = $comments_count.' Comments';
}
else
{
$comment = 'There are no comments at the moment.<br />'.$commenting_form;
$page_title = 'No Comments';
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><?php echo $page_title; ?></title>
</head>
<body>
<?php
echo $comment;
?>
</body>
</html>
Try this:
include "../connect.php";
NOTE: make sure you put the right path of connect.php
My code below does not work.
nisreen is the name of DB , and the table name is ana.
What I want is to read the path of the SWF file from the database, then view it on the web-page.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<?php
$con =mysql_connect("localhost","root","");
mysql_select_db("nisreen", $con);
$result = mysql_query("SELECT * FROM ana LIMIT 1");
while($row = mysql_fetch_array($result))
{
$row['title'];
}
echo '</head>';
echo '<body>';
echo $row;
echo '<object data="'.$row . "'";
echo "type='application/x-shockwave-flash' width='600' height='600'>";
echo '</object>';
echo '
</body>
</html>';
?>
You're not assigning your fetched data to a variable, $row exists only in the scope of that while loop. try something like
<?php
$con =mysql_connect("localhost","root","");
mysql_select_db("nisreen", $con);
$result = mysql_query("SELECT * FROM ana LIMIT 1");
while($row = mysql_fetch_array($result))
{
$title = $row['title'];
$path = $row['path'];
}
echo '</head>';
echo '<body>';
echo $title;
echo '<object data="'.$path. "'";
echo "type='application/x-shockwave-flash' width='600' height='600'>";
echo '</object>';
echo '
</body>
</html>';
?>
i want to show the StudentNo, SubjectCode,SubjectDescription and grade but when ever students get failing grade it generates another entry for all the fields so what i want is to show the studentNo, SubjectCode, and SubjectDescription once while showing the 2 grades in that particular subject of that student..
Example:
I want to show only like this:(
07-08-061 EN110 5 / 1)
Here's my Code:
**
mysql_select_db($database_strawman, $strawman);
$query_Recordset1 = "SELECT curriculum.SCode, curriculum.SDesc, grade.Grade, students.StudNo FROM students INNER JOIN (curriculum INNER JOIN grade ON curriculum.SCode = grade.GSCode) ON students.StudNo = grade.GStudNo GROUP BY StudNo";
$Recordset1 = mysql_query($query_Recordset1, $strawman) or die(mysql_error());
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table width="200" border="1">
<tr>
<td>Subject Code</td>
<td>Subject Description</td>
<td>Grade</td>
<td>Student Number</td>
</tr>
<?php while($row_Recordset1 = mysql_fetch_assoc($Recordset1)){ ?>
<tr>
<td><?php echo $row_Recordset1['SCode']; ?></td>
<td><?php echo $row_Recordset1['SDesc']; ?></td>
<td><?php echo $row_Recordset1['Grade']; ?></td>
<td><?php echo $row_Recordset1['StudNo']; ?></td>
</tr>
<?php } ?>
</table> </p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
**
Try using GROUP_CONCAT instead of SUM for your aggregate function:
SELECT c.SCode, c.SDesc, GROUP_CONCAT(g.Grade), s.StudNo
FROM students s
INNER JOIN grade g
ON s.StudNo = g.GStudNo
INNER JOIN curriculum c
ON g.GSCode = c.SCode
GROUP BY c.SCode, c.SDesc, s.StudNo
you can add a where clause
like
where grade > 1
(insert the minimum grade to pass)
Group by student number and code, use group_concat to get the 2(+) grades listed out of the grouping.
SELECT *, group_concat(grade) as grades FROM students GROUP BY GSTudNo, GSCode
Thats the basics, to use your query it'd be something like:
SELECT curriculum.SCode, curriculum.SDesc, SUM(grade.Grade) grade_total, students.StudNo, group_concat (grade.Grade) as grades
FROM students
INNER JOIN (curriculum INNER JOIN grade ON curriculum.SCode = grade.GSCode)
ON students.StudNo = grade.GStudNo
GROUP BY StudNo, GSCode