Database Structure For orders - php

I need some ideas on how to edit my structure inside my database I am building a fast food order website for 1 take away client at the moment the user adds there items into the order table
Here is it the table: http://prntscr.com/g3o3kz
The user_id column is for the user who is ordering id to be stored then item id is what item they want takeawayid is the id of the take away and the status is were they order food its auto set to waiting then the take away can update it to accepted or declined.
Now the problem I'm having is the user adds 5 items into the table above for take away id 1 there will be 5 rows for the user id and take away id and item id (there are 5 items)
Now I'm onto the recent orders page and I print out all for each take away so like so
http://prntscr.com/g3o4uw
But then tomorrow if they order it will add another 5 items and it will show in the same box how would I group each order? So order 1 has xyz items then next time the order order2 has xyz and so on. because at the moment the way the database is laying out it will just all be order1 if this makes sense
Displaying the orders box
<div class="container" style="margin-top: 40px;">
<div class="row">
<div class="col-xs-12">
<?php
echo $_SESSION['username'] ;
foreach ($ordersByUsers as $userId => $item) {
$username = $item['username'];
$ordersPrice = $item['ordersPrice'];
$orders = $item['orders'];
?>
<div class="row">
<div class="col-xs-12 col-md-10" style="background-color: #FAFAF8; border: 1px solid #ddd; padding: 20px; margin-bottom: 20px;">
<div class="row" style="padding: 20px;">
<div class="col-xs-12 col-sm-3">
<div class="row">
<a href="#">
<img src="http://santetotal.com/wp-content/uploads/2014/05/default-user.png" class="img-responsive" alt="Restaurant logo" height="92" width="102">
</a>
</div>
<div class="row" style="padding-top: 10px;">
<a href="#" style="text-transform: uppercase;">
<?php echo $username; echo "<br> </br>";
?>
<?php
/////////// get status of order
$statement8 = $db->prepare("SELECT * FROM users WHERE username = ? ");
$statement8->execute(array($_SESSION['username']));
$count8 = $statement8->fetch();
$username233 = mysql_real_escape_string($count8['id']);
$username2312312 = strip_tags($username233);
$statement85 = $db->prepare("SELECT * FROM orders WHERE user_id = ? AND takeawayid = ? ");
$statement85->execute(array($username2312312,$_SESSION['userid']));
$count84 = $statement85->fetch();
if($count84 ['status']== "waiting") {
?>
<form action="dashboard.php" method="post">
<input type="hidden" name="accept" value="<?php echo $count84['id']?>">
<input type="image" name="submit" src="http://business.fsdfsdfsdf.com/beta/accept.png" border="0" alt="Submit" />
</p>
</form>
<form action="dashboard.php" method="post">
<input type="hidden" name="deny" value="<?php echo $count84['id']?>">
<input type="image" name="submit" src="http://business.sdfsdfdf.com/beta/deny.png" border="0" alt="Submit" />
</p>
</form>
<?php
}elseif ($count84 ['status']== "Accepted") {
echo "<img src='http://business.sfdfsdfsdf.com/beta/accepted.png' alt='error'>";
} else {
echo "<img src='http://business.sdfdsfsdfsdf.com/beta/declined.png' alt='error'>" ;
}
?>
</a>
</div>
</div>
<div class="col-xs-12 col-sm-9">
<?php
foreach ($orders as $order) {
$orderId = $order['orderId'];
$itemname = $order['itemname'];
$price = $order['price'];
$date = $order['date'];
$address = $order['address'];
?>
<div class="row">
<div class="col-xs-12" style="background-color: #FFF; border: 1px solid #ddd; padding: 20px; margin-bottom: 20px;">
<h4>
<a href="profile.html" style="color: orange;">
<?php echo $itemname; ?>
</a>
</h4>
<div>
<div>
<span>
<?php echo $date; ?>
</span>
</div>
<div class="ratings">
<span>5 STARS</span>
</div>
</div>
</div>
Address: <b> <?php echo $address; ?></b>
</div>
<?php
}
?>
</div>
</div>
</div>
<div class="col-xs-12 col-md-2" style="padding: 20px; padding-top: 40px; font-size: 20px; color: #666; text-transform: uppercase;">
Total: <?php echo $ordersPrice; ?>
</div>
</div>
<?php
}
?>
query
function fetchPaidOrdersByTakeaway($connection, $takeawayId, $paid) {
if (!isset($takeawayId)) {
throw new Exception('Takeaway ID not provided!');
}
if (!isset($paid)) {
throw new Exception('Paid not provided!');
}
// Sql statement.
$sql = 'SELECT
ord.id AS orderId,
usr.id AS userId,
usr.username,
ord.itemname,
ord.address,
ord.price,
ord.date
FROM orders AS ord
LEFT JOIN users AS usr ON usr.id = ord.user_id
WHERE
user_id = :takeawayid
AND paid = :paid
ORDER BY
usr.username ASC,
ord.date DESC';
// Prepare and check sql statement (returns PDO statement).
$statement = $connection->prepare($sql);
if (!$statement) {
throw new Exception('The SQL statement can not be prepared!');
}
// Bind values to sql statement parameters.
$statement->bindValue(':takeawayid', $_SESSION['userid'], getInputParameterDataType($_SESSION['userid']));
$statement->bindValue(':paid', $paid, getInputParameterDataType($paid));
// Execute and check PDO statement.
if (!$statement->execute()) {
throw new Exception('The PDO statement can not be executed!');
}
// Fetch data.
$fetchedData = $statement->fetchAll(PDO::FETCH_ASSOC);
if ($fetchedData === FALSE) {
throw new Exception('Fetching data failed!');
}
return $fetchedData;
}
/**
* Group orders by users.
*
* #param array $orders [optional] Orders list.
* #return array Orders list grouped by users.
* #throws Exception
*/
function groupOrdersByUsers(array $orders = array()) {
$groupedOrders = array();
foreach ($orders as $order) {
$userId = $order['userId'];
$username = $order['username'];
$price = $order['price'];
// Check and add user name as key, if not already.
if (!array_key_exists($userId, $groupedOrders)) {
$groupedOrders[$userId] = array(
'username' => $username,
'orders' => array(),
'ordersPrice' => 0,
);
}
// Add order to grouped orders list.
$groupedOrders[$userId]['orders'][] = $order;
$groupedOrders[$userId]['ordersPrice'] += $price;
}
return $groupedOrders;
}
would i need a extra column maybe orderid then have all the order the same id then display each by order id ?Problem is adding the same number to each item inside the order then next order adding a new number and not having 2 the same numbers
Edit
at the moment i show there cart like so
$statement = $db->prepare("SELECT * FROM orders WHERE user_id = ? AND status = ? AND takeawayid = ? ");
// $statement->execute(array($username2,$md5password,$mod));
$statement->bindParam(1, $_SESSION['userid'], PDO::PARAM_STR, 50); // check your lengths
$statement->bindParam(2, $testing, PDO::PARAM_STR, 60);
$statement->bindParam(3, $id1, PDO::PARAM_INT);
$statement->execute();
this of course works perfect because old orders will ether be accepted or declined so the waiting status ones will be the current ones. Im just finding it hard to print out old orders and group them together

Learn how to achieve third normal form for your database.
That magic phrase simply means that if you have something may be isolated as one entity - create a separate table for it.
In your case there should be 1 table for orders and 1 table for items, tables will be joined with foreign keys, which in Mysql are made as said in that article: MySQL foreign key examples (How to define foreign keys in MySQL)
To untie your imagination with proper tool I would recommend you to use MySQL Workbench which will help you to visualize database structure while you will design it. It may be a "From a cannon by a sparrow" approach in your particular case but will definitely help to rapidly advance your skills in future.
And finally answering your question in detail
Create items table with id, name and price fields. It will contain list of items you are offering to your users
id will be Primary key with auto increment property
Create users table with id and name fields
id will be Primary key with auto increment property
Create orders table with id and user_id fields
id will be Primary key with auto increment property
user_id will have Foreign key linked with users table
Create order_items table with id, order_id, price and quantity fields
id will be Primary key with auto increment property
order_id will have Foreign key linked with orders table
item_id will have Foreign key linked with items table
I can't understand what address and date fields are for, so attach then to appropriate table listed above.
As a result you will have list of orders for every user, with a list of items ordered inside connected with price-list. You will be able to SELECT all the joined data from all tables at once OR a part of data to show it to user or to you.
The great thing here is that there is no problem with IDs anymore.

Related

Erro: I cannot show the checkboxes in checked state without the same checkbox being repeated more than 1 time

Table structure
<?php
//the grupo_usuarios table contains the database user groups
CREATE TABLE `grupo_usuarios` (
`id` int(11) NOT NULL AUTOINCREMENT,
`nombre` varchar(20) COLLATE utf8_spanish_ci NOT NULL,
`descripcion` varchar(150) COLLATE utf8_spanish_ci NOT NULL
);
//the permisos table contains the permissions
CREATE TABLE `permisos` (
`id` int(11) PRIMARY KEY NOT NULL AUTOINCREMENT,
`nombre` varchar(20) COLLATE utf8_spanish_ci NOT NULL
);
// the table tiene_asignado is the result of the many-to-many relationship between the grupo_usuarios table and permisos
CREATE TABLE `tiene_asignado` (
`id` int(11) PRIMARY KEY NOT NULL AUTOINCREMENT,
`id_grupo` int(11) NOT NULL,
`id_permisos` int(11) NOT NULL,
FOREIGN KEY(id_grupo) REFERENCES grupo_usuarios(id),
FOREIGN KEY(id_permisos) REFERENCES permisos(id),
ON DELETE CASCADE ON UPDATE CASCADE
);
?>
<?php include('php/verificarSesion.php');?>
<?php
//Storing the id of the user group received through GET from the groups.php page
if(isset($_GET['id_grupo_usuarios']) && (!empty($_GET['id_grupo_usuarios'])) && is_numeric($_GET['id_grupo_usuarios']) == 1){
$id_grupo_usuarios = $_GET['id_grupo_usuarios'];
}else{
echo "<script>
window.location.href='verGrupo.php';
</script>";}
?>
<?php include("plantillas/header.php"); ?>
<!-- PAGE CONTENT (permisosChex.php)-->
<section class="listadoPacientes">
<div class="container mt-3">
<div class="row">
<div class="col-6 col-md-5">
<h2>Assign permissions to the group <?php echo $id_grupo_usuarios;?></h2>
<p>Here you can check the permissions belonging to this group</p>
</div>
<div class="col-4" id="tabla">
<table id="tablaPacientes" class="table table-bordered table-striped" style="width:100%">
<thead>
<tr>
<th>Permissions</th>
</tr>
</thead>
<tbody>
<!--START OF THE DATA SUBMISSION FORM-->
<form class="row formularioCrearPaciente" action="php/asignarPermisos.php" method="post" id="FormularioActualizarPaciente">
<input type="text" value="<?php echo $id_grupo_usuarios; ?>" name="id_grupo_usuarios">
<?php include("php/conexion.php")?>
<?php
//query to display all permissions
$sql = "SELECT * FROM permisos ORDER BY id DESC";
$resultado = $conexion->query($sql);
$listadoPermisos = array('data' => array());
if($resultado->num_rows > 0) {
//we will show a numbering in the table>>>>numbering: 1, 2, 3....
$numeracion = 0;
while($fila = $resultado->fetch_array()) {
$numeracion = $numeracion + 1;
//the permit id is stored here
$id_permiso = $fila[0];
$nombre = $fila['nombre'];
In this second query I get the permissions assigned to a group of users
$consulta2 = "SELECT id_permisos FROM tiene_asignado where id_grupo = $id_grupo_usuarios";
$resultados = $conexion->query($consulta2);
while( $asignados = $resultados->fetch_array()){
//here I store the permissions of the selected checkboxes
$datos=array();
if (is_array($asignados) == true) {
//I assign a variable for each selected checkbox in the array
foreach($asignados as $asignado)
{
I relate the permissions selected from the checkbox with the id_permisos field of the table (tiene_asignado)
$datos[$asignados['id_permisos']] = true;
}
}else{//END OF is_array($asignados)
//this is just a test
echo "nothing";
}
?>
<tr>
<td>
<?php echo $numeracion;?>
<input title='create sheet of <?php echo $id_grupo_usuarios?>' type="checkbox" name="permisos[]" value="<?php echo $id_permiso;?>" class="delete-checkbox" <?php echo isset($datos[$fila[0]]) ? 'checked' : '';?> >
</tr
I can only see the permissions assigned to the group when I include the input checkbox inside the second WHILE if I don't do it like that, the problem is that the inputs are also repeated, that is, if a group has 3 permissions assigned, each one of the inputs are repeated three times but it shows me the 3 permissions assigned to that group
<?php } //END OF THE SECOND WHILE?>
<?php } //END OF THE FIRST WHILE?>
<?php
} //END OF IF?>
<?php ?>
<div class="col-md-6 form-group">
<button type="submit"id="ActualizarPaciente" class="btn btn-primary">Asignar Permisos</button>
</div>
</form>
<?php
?>
</div>
</div>
</div>
</tbody>
</table>
</div>
</div>
</div>
</section>
<!-- END OF PAGE CONTENT -->
<!-- Including the footer of the page -->
<?php include('plantillas/footer.php'); ?>
<!-- script js which contains the functionalities of the permission list page -->
<!--<script src="js/verpermisosChex.js"></script>-->
You are selecting all records from permisos and for each record you select all records from tiene_asignado which are in the id_grupo that's matching a value. However, it is clear that your permisos table is logically related to tiene_asignado via the id_permisos field.
So, let's take a look at your second query: it is only loading id_permisos from tiene_asignado and it is safe to assume that your permisos table has an id, maybe called id_permisos, maybe having a different name and you have already loaded the id_permisos value using your first query.
As a result, your second query seems to be unnecessary, so, you will need to remove the second query and the second while (of course, you need the content of the second while, but it does not need to be a loop). If for some reason you need to load from tiene_asignado anyway, then you can modify your first query to be a join. However, if you need help with modifying your first query, you will need to provide information about your tables, at least their fields.
EDIT
based on subsequent information found out since this answer was originally written, I recommend the usage of the following query:
$sql = "SELECT * FROM permisos p LEFT JOIN tiene_asignado ta ON p.id = ta.id_permisos AND id_grupo='".$id_grupo_usuarios."' ";)

Cannot group table values by ID

Hey there guys/girls I have an issue I'm currently trying to work through being a novice to MYSQL / PHP. Currently I'm using Bootstrap accordion collapsible components to display HTML tables (That are reports). Here is my current table:
Current Table in MYSQL.
So as you can see the reports row contains some HTML information which are tables. I wanted to take the information and display it on a webpage assuming that every row was a different report. So I was able to do so with writing this:
<div class="accordion" id="accordionExample">
<?php
require('db.php');
$i = 0;
$sql = "SELECT `report` FROM `automation-reports`;";
$query = mysqli_query($connection, $sql);
while($row = mysqli_fetch_assoc($query))
{
foreach($row as $key => $value)
{
?>
<div class="card">
<div class="card-header" id="heading<?php echo $i ?>">
<h5 class="mb-0">
<button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapse<?php echo $i ?>" aria-expanded="true" aria-controls="collapse<?php echo $i ?>">
Report #1: 8/6/2018
</button>
</h5>
</div>
<div id="collapse<?php echo $i ?>" class="collapse" aria-labelledby="heading<?php echo $i ?>" data-parent="#accordionExample">
<div style="text-align: center;" class="card-body">
<h3 style="float: left;"> Rating-Pull: </h3>
<?php
$i++;
echo $key;
echo "$value";
?>
</div>
</div>
</div>
<?php
}
}
?>
</div>
Which is great because it does what I thought I wanted it to do , which is this:
Display Output
What's not so great is now I realize that multiple reports are going to be in one accordion "folder" which is where the reportid row comes into play. So lets say I run my program and two (different) reports run on it but I want it in the say "folder" on the webpage. Both of these get labeled with a reportid of 1.
So what I want to do is loop through reports and then if they have the same ID group them together in that folder and iterate through the whole table like that. So that's the part where I have attempted to do so with a nested loop and SELECT 'report' FROM 'automation-reports' WHERE 'reportid' = '$i' ; and I just ended up getting the first element. Could somebody give me a hand with this and a good explanation so I can understand and learn what's happening?
Thank you!
EDIT:
Maybe a visual would be better?
VISUAL
I think GROUP BY and GROUP_CONCAT are what you are looking for.
SELECT `reportid`, GROUP_CONCAT(`report` SEPARATOR '') as report
FROM `automation-reports`
GROUP BY `reportid`
shoud do the job.
SELECT *
FROM `automation-reports`
GROUP BY `reportid`
will give you one row for each id ie.
id 1,
id 2,
id 3
Or do you want to display each row like so?
id 1, id 1,
id 2,
id 3, id 3,
id 4
if so here is a possible example of combining the reports in a loop first
$sql = "SELECT reportid, GROUP_CONCAT(report SEPARATOR ',') as reports FROM `automation-reports` GROUP BY `reportid`;";
while($row = mysqli_fetch_assoc($query)) {
echo "<div id='{$row['reportid']}'>";
echo $row['reports'];
echo "</div>";
}
I know this isn't the HTML you're after but you should be able to place your HTML in this code

hide button after saving data to database

i created a group and what i wanted to do is when i join the group the join button should hide. but i dont know how to do it.. tbl_group is the list of created group and when you join the group the id will be saved on a diff table.. this code is for showing all list of groups.
group.php
<?php
$db = new Group($conn);
$res = $db->g_viewlist();
foreach ($res as $key => $value){
?>
<div class="col-lg-12" align="center" style="border:1.5px solid #59960b;padding-bottom:10px;padding-top:10px;">
<button class="btn2 btn-2 join" data-id="<?php echo $value['g_id']; ?>" data-toggle="modal" data-target="#joinModal" style="padding: 2px 2px;margin-left:50%"><strong> Join</strong></button>
<img src="./<?php echo $value['g_image']; ?>"class="pull-left" class="img-square" height="70" width="70" alt="Avatar">
<p align="left">
<strong class="font-1" style="color:#59960b;"><?php echo $value['g_name'];?> </strong><br>
<small style="font-family:courier,'new courier';" class="text">Member Since 2008<br></small>
<small style="font-family:courier,'new courier';" class="text-muted">Description:<?php echo $value['g_desc']; ?></small><br>
</p>
</div>
<?php
}
?>
SQL Query for showing all list of groups.
public function g_viewlist(){
$sql = "SELECT * FROM tbl_group ";
$result = $this->dbh->prepare($sql);
$result->execute();
$data = array();
while($row = $result->fetch(PDO::FETCH_ASSOC)){
$data[] = $row;
}
return $data;
}
this table is where i store the user id and the group id this is a diff table..assuming the g_id = 25 from tbl_group and group_id =25 from tbljoingroup
You need to retrieve the array of groups user is a member of and inside your foreach loop just search through this list. If user is a member of $value['g_id'] just skip loop iteration with continue.
If you want to hide only the button and still display the rest of the code then do something like this:
<?php
$db = new Group($conn);
$res = $db->g_viewlist();
foreach ($res as $key => $value) {
?>
<div class="col-lg-12" align="center" style="border:1.5px solid #59960b;padding-bottom:10px;padding-top:10px;">
<?php if (!$user.memberOf($value['g_id'])) { ?>
<button class="btn2 btn-2 join" data-id="<?php echo $value['g_id']; ?>" data-toggle="modal" data-target="#joinModal" style="padding: 2px 2px;margin-left:50%"><strong> Join</strong></button>
<?php } ?>
<img src="./<?php echo $value['g_image']; ?>"class="pull-left" class="img-square" height="70" width="70" alt="Avatar">
<p align="left">
<strong class="font-1" style="color:#59960b;"><?php echo $value['g_name'];?> </strong><br>
<small style="font-family:courier,'new courier';" class="text">Member Since 2008<br></small>
<small style="font-family:courier,'new courier';" class="text-muted">Description:<?php echo $value['g_desc']; ?></small><br>
</p>
</div>
<?php
}
?>
If you have user object saved in $user then create memberOf() method which will return true if user is a member of the group or false otherwise.
Note: Do not search database on each memberOf() execution. Do it once and save results in object's property for reuse.

Return Value in Column B Table 2, where column A Table 1, matches Column A Table 2

What I'm trying to do: Where category (projects) matches id (markets) echo category (markets).
Table 1 Sample (projects table)
Table 2 Sample (markets table)
Sample of PHP Code
$num_rec_per_page=5;
if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
$start_from = ($page-1) * $num_rec_per_page;
function GET($key) {
return isset($_GET[$key]) ? $_GET[$key] : null;
}
$category= GET('category');
if ($category !== null) {
$sql = "SELECT * FROM projects WHERE category='$category' LIMIT $start_from, $num_rec_per_page";
} else {
$sql = "SELECT * FROM projects LIMIT $start_from, $num_rec_per_page";
}
$sql_query = mysql_query($sql);
$post = $sql_query;
$sql1 = "SELECT * FROM markets";
$sql_query1 = mysql_query($sql1);
$marketsinfo = mysql_fetch_array($sql_query1);
In my code below, I've tried putting a while loop within the main while loop since we have to find out what category its in then display it for each blog post.
It only worked for the first result, and then I did some research online and found that it is very poor design to do this.
Where I'm currently at with displaying the result (see code in between hyphens):
<!-- Blog - Start -->
<?php while ($post = mysql_fetch_array($sql_query)) {?>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 blog blog_altered blog_left">
<div class="row">
<!-- Blog Image - Start -->
<div class=" col-lg-6 col-md-6 col-sm-10 col-xs-12 pic inviewport animated delay1" data-effect="fadeIn">
<img alt="blog-image" class="img-responsive" src="<?php echo $post['imageoutside'] ?>">
</div>
<!-- Blog Image - End -->
<!-- Blog Info - Start -->
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 inviewport animated delay1" data-effect="fadeIn">
<div class="info">
----------------------------------------------------------------------
<span class="date">
<?php
if($post['category'] === $marketsinfo['id']){
echo $marketsinfo['category'];
}
?>
</span>
----------------------------------------------------------------------
<h4 class="title"><?php echo $post['title'] ?></h4>
<p><?php echo $post['summary'] ?></p>
<a class="btn btn-primary text-on-primary" href="projects/readmore.php?job=<?php echo $post['job'] ?>">Read More</a>
</div>
</div>
<!-- Blog Info - End -->
</div>
</div>
<?php } ?>
<!-- Blog - End -->
Hope I've been thorough enough without being confusing. How can a noob accomplish this? I'll take any pointers you have!!
If you use a join, you can get the category text in one query and avoid all the looping in PHP.
A LEFT Join will return all records from Projects and only those records which match from markets. So if a projects category doesn't exist in markets, a NULL value will be returned.
If you used a INNER JOIN, only records which have corresponding values in BOTH tables would be returned.
Rule of thumb: get the data you need from the database in 1 trip when you need it. Format in PHP, Datagrab in SQL. Don't get more than you need, and don't get less.
SELECT P.Job, M.ID as Markets_ID, M.Category, P.Title
FROM projects P
LEFT JOIN Markets M
on P.Category =M.ID
WHERE P.category='$category'
LIMIT $start_from, $num_rec_per_page"
Note: you will need to put a table alias on category in the where clause. I'm assuming your passing in the ID so P.Category was used.
do you want join table projects with tables market by category?
may be u can do this
SELECT p.id as id
, m.category as category
from projects as p
left
join markets as m
on p.category = m.id
WHERE m.category='$category'
LIMIT $start_from
, $num_rec_per_page

Different Order numbers for same patient only allows me to get one from DB

So I have a table called Orders.
In this table I have
ordernum
name
Everytime I add a new order it creates a new order number the name only changes if I change it... So for instance..
Donald could have 20 different orders in that table..
Now I am trying to display all the order numbers for Donald
This is my current code.
<?php
$blue = $_SESSION['name']; // This is the customers name
$sqll = "SELECT * FROM orders WHERE name = :blah";
$qq=$con->prepare($sqll);
$qq->bindparam(":blah", $blue);
$qq->execute();
$u=$qq->fetch(PDO::FETCH_ASSOC);
?>
<div class="sectionContent">
<div class="sectionFull">
<div class="sectionOneHalf">
<fieldset>
<legend>Orders</legend>
<ol>
<li>
<label>Orders</label>
// Here I am trying to display all the different order numbers in teh table that are listed under his name
<div class="OrdersContainer">
<?php echo $u['ordernum'];?>
</div>
</li>
</ol>
<br>
</fieldset>
</div>
</div>
Problem is, When I try to list those orders now... I only get one that shows up.
I need to display them all for that specific persons name
The problem is you're fetching only one row from the result set. Loop through the result set to display all orders, like this:
while($u=$qq->fetch(PDO::FETCH_ASSOC)){
// display orders
}
Your code should be like this:
// your code
<li>
<label>Orders</label>
<div class="OrdersContainer">
<?php
while($u=$qq->fetch(PDO::FETCH_ASSOC)){
// display orders
echo $u['ordernum'] . "<br />";
}
?>
</div>
</li>
// your code
<?php
$blue = $_SESSION['name']; // This is the customers name
$sqll = "SELECT * FROM orders WHERE name = :blah";
$qq=$con->prepare($sqll);
$qq->bindparam(":blah", $blue);
$qq->execute();
?>
<div class="sectionContent">
<div class="sectionFull">
<div class="sectionOneHalf">
<fieldset>
<legend>Orders</legend>
<ol>
<li>
<label>Orders</label>
// Here I am trying to display all the different order numbers in teh table that are listed under his name
<div class="OrdersContainer">
<?php
while($u=$qq->fetch(PDO::FETCH_ASSOC))
{
echo $u['ordernum'];
}
?>
</div>
</li>
</ol>
<br>
</fieldset>
</div>
</div>
</div>
Change fetch to fetchall should solve your problem, you appear to be fetching only a single row so thats all you will get.
Instead of
$u=$qq->fetch(PDO::FETCH_ASSOC);
use
$u=$qq->fetchAll(PDO::FETCH_ASSOC);
You can try this:
$blue = $_SESSION['name']; // This is the customers name
$sqll = "SELECT * FROM orders WHERE name = :blah";
$qq=$con->prepare($sqll);
$qq->bindparam(":blah", $blue);
$qq->execute();
while ($row = $qq->fetch(PDO::FETCH_ASSOC)) {
// your html
echo $row['ordernum'] . "\n";
// your html
}
What Change?
Adding while loop

Categories