I've read a ton of different ideas out there for this but can't seem to get any of them to work for my piece of code. Currently my products are displaying in a singular column but I'd like them to display in either a 3 or 4 column grid. Here's the code I have so far, hopefully someone can see where I'm going wrong.
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) { ?>
<div class="container">
<div class="col-sm-4">
<?php echo $row["ID"] . " - " . $row["item"] . "<br>";?>
<img src="img/<?php echo $row["image"] ?>" style="width:150px;height:150px;"><br>
<?php echo $row["description"] . " - $" . $row["price"]; ?>
<form method="post" action="viewcart.php">
<input type="hidden" name="item" value="<?php echo $row["item"]?>" />
<input type="hidden" name="price" value="<?php echo $row["price"]?>" />
<button type="submit">Add To Cart</button>
</form>
</div>
</div>
You have the .container being looped inside the while loop as well, which is the problem. The correct format is:
.container
.row
.col-XX-X
Put the container and the row outside and you are good to go.
<?php
if ($result->num_rows > 0) {
echo '<div class="container"><div class="row">'; // You left a row. Change here.
while($row = $result->fetch_assoc()) { ?>
<div class="col-sm-4">
<?php echo $row["ID"] . " - " . $row["item"] . "<br>";?>
<img src="img/<?php echo $row["image"] ?>" style="width:150px;height:150px;"><br>
<?php echo $row["description"] . " - $" . $row["price"]; ?>
<form method="post" action="viewcart.php">
<input type="hidden" name="item" value="<?php echo $row["item"]?>" />
<input type="hidden" name="price" value="<?php echo $row["price"]?>" />
<button type="submit">Add To Cart</button>
</form>
</div>
<?php } ?>
</div>
</div>
Put your container outside of while loop:
if ($result->num_rows > 0) {
echo '<div class="container">';
while($row = $result->fetch_assoc()) { ?>
<div class="col-sm-4">
<?php echo $row["ID"] . " - " . $row["item"] . "<br>";?>
<img src="img/<?php echo $row["image"] ?>" style="width:150px;height:150px;"><br>
<?php echo $row["description"] . " - $" . $row["price"]; ?>
<form method="post" action="viewcart.php">
<input type="hidden" name="item" value="<?php echo $row["item"]?>" />
<input type="hidden" name="price" value="<?php echo $row["price"]?>" />
<button type="submit">Add To Cart</button>
</form>
</div>
<?php } // end while loop
?>
</div>
<?php } //end if statement
?>
If you want more columns, make it like below:
<div class="container">
<div class="row">
<div class="col-sm-4">
</div>
<div class="col-sm-6">
</div>
<div class="col-sm-2">
</div>
</div>
</div>
The total number of columns when you add up, must be 12
Related
I have a mysql data which I call to display to my PHP table and then for example I clicked the username01, I wanted to call the other columns of that username01 (e.g. password01, id01) to display to my modal fields.
Here's my code:
PHP
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" ?> <?php echo "<font color='blue'>" . $row['ipaddress'] . "</font></td>";
echo "<td>" . $row['name'] . "</td>";
Modal
<?php
include 'includes\dbconn.php';
$query = mysqli_query($conn,"SELECT * from devopstbl where id=$id");
$ipaddress = $row['ipaddress'];
$name = $row['name'];
$department = $row['department'];
?>
<div id="id01" class="modal">
<form class="modal-content animate" method="GET" action="ipaddress.php">
<div class="imgcontainer">
<span onclick="document.getElementById('id01').style.display='none'" class="close" title="Exit">×</span>
<img src="images/avatar.png" alt="Avatar" class="avatar">
</div>
<div class="container">
<label for="ipaddress"><b>Username <?php echo $username; ?></b></label>
<input type="text" pattern="[a-zA-Z0-9\s]+" name="username" value="<?php echo $ipaddress; ?>" required>
Apparently.. the $id only gets the id01 even i clicked the other data like id02 etc. and does not get its other columns like username01 password01..
Am i missing something?
Put yout Modal-part to while loop.
while($row = mysqli_fetch_array($result))
{
$id = $row['id'];
$username = $row['username'];
$ipaddress = $row['ipaddress'];
$name = $row['name'];
echo '<tr>
<td>
<font color="blue">'.$ipaddress.'</font>
<div id="id'.$id.'" class="modal">
<form class="modal-content animate" method="GET" action="ipaddress.php">
<div class="imgcontainer">
<span onclick="document.getElementById(\'id'.$id.'\').style.display=\'none\'" class="close" title="Exit">×</span>
<img src="images/avatar.png" alt="Avatar" class="avatar">
</div>
<div class="container">
<label for="ipaddress"><b>Username '.$username.'</b></label>
<input type="text" pattern="[a-zA-Z0-9\s]+" name="username" value="'.$ipaddress.'" required>
</div>
</form>
</div>
</td>
<td>'.$name.'</td>
';
}
I'm tryin to make a simple online shopping page for my PHP training.
But, I'm kinda stuck in the HTML part where using bootstrap didn't make
something more simpler.
The result of the code makes my product line up vertically, and what I want to with it is to make it line up horizontally.
Code :
<div class="container">
<?php
$connect = mysqli_connect('localhost', 'root', '', 'cart');
$query = 'SELECT * FROM products ORDER by id ASC';
$result = mysqli_query($connect, $query);
if ($result):
if (mysqli_num_rows($result)>0):
while ($product = mysqli_fetch_assoc($result)):
//print_r($product);
?>
<div class="col-sm-4">
<form class="" action="welcome.php?action=add&id=<?php echo $product['id'] ?>" method="post">
<div class="products">
<img src="<?php echo $product['image']; ?>" class="img-fluid text-center" />
<h4 class="text-info"><?php echo $product['name']; ?></h4>
<h4>$ <?php echo $product['price']; ?></h4>
<input type="text" name="quantity" class="form-control" value="1" />
<input type="hidden" name="name" value="<?php echo $product['name'] ?>" />
<input type="hidden" name="price" value="<?php echo $product['price']; ?>" />
<button type="submit" name="add_to_cart" class="btn btn-outline-primary">Add to Cart</button>
</div>
</form>
</div>
<?php
endwhile;
endif;
endif;
?>
For bootstrap grid system to work , the tags must be in following order:
<div class="container">
<div class="row">
<div class="col-md-6">
One of two columns
</div>
<div class="col-md-6">
One of two columns
</div>
</div>
</div>
post id is the common field in both the tables.If I want to select the comments under same post_id,only 1 time the post should display and all its comments under it..
this is my code....
home.php
<?php
$sql="SELECT family_news.post_id,family_news.username,family_news.post,
family_news.fileToUpload,family_news.description,
family_comments.post_id,family_comments.comment,
family_comments.commenter
FROM family_news
LEFT JOIN family_comments ON family_news.post_id = family_comments.post_id
ORDER BY family_news.post_id DESC";
if($result = mysqli_query($con, $sql))
{
while($row = mysqli_fetch_array($result))
{
?>
<div class="form-group">
<b style="font-size:30px;color:brown;">
<?php
echo $row['username'];
?>
</b>
<br>
<?php
if($row['fileToUpload'] != NULL)
{
?>
<form action="post_comment.php" method="POST">
<input class="form-control" type="hidden" name="post_id" value="<?php echo $row['post_id']; ?>">
<br>
<img class="img-responsive" src="../admin_panel/uploads/<?php echo $row['fileToUpload']; ?>" alt="Image Loading" height='80' width='120'>
<div class="form-group" style="font-size:15px;color:purple;">
<?php
echo $row['description'];
?>
<br>
<h3 style="color:black">Comments</h3>
<h3 style="color:red">
<?php
echo $row['commenter'];
?>
</h3>
<h4 style="color:saddlebrown">
<?php
echo $row['comment'];
?>
</h4>
<br>
<input class="form-control" type="text" name="comment" placeholder="Write a comment">
<br>
<input class="form-control" type="hidden" name="commenter" value="<?php echo $_SESSION['uname']; ?>">
<input type="submit" class="btn btn-primary" value="Post">
</div>
</form>
<?php
}
if($row['post'] != NULL)
{
?>
<br>
<div class="form-group" style="font-size:15px;color:purple;">
<form action="post_comment.php" method="POST">
<input class="form-control" type="hidden" name="post_id" value="<?php echo $row['post_id']; ?>">
<?php
echo $row['post'];
?>
<br>
<h3 style="color:black">Comments</h3>
<h3 style="color:red">
<?php
echo $row['commenter'];
?>
</h3>
<h4 style="color:saddlebrown">
<?php
echo $row['comment'];
?>
</h4>
<br>
<input class="form-control" type="text" name="comment" placeholder="Write a comment">
<br>
<input class="form-control" type="hidden" name="commenter" value="<?php echo $_SESSION['uname']; ?>">
<input type="submit" class="btn btn-primary" value="Post">
</form>
<?php
}
?>
</div>
<?php
}
}
?>
</div>
</section>
post_comment.php
<section class="col-lg-6 connectedSortable">
<?php
$post_id=$_POST['post_id'];
$comment=$_POST['comment'];
$commenter=$_POST['commenter'];
if($comment != NULL) {
$sql="INSERT INTO family_comments
(post_id, comment, commenter)
VALUES ('$post_id', '$comment', '$commenter')";
if($con ->query($sql) == TRUE)
{
echo 'Comment saved Successfully...';
}
} else {
echo 'Please Write Something...';
}
?>
</section>
I'm trying to populate a drop down from values in DB on the same page which is from input on the same page itself.
I have tried a few options on the forum but it did not help.
After hitting submit it goes to a next page which is blank.
I have tried onchange=AjaxFunction(); as suggested in one post, but i still get a blank page.
Any help is appreciated.
This is my form.php
<form action="connection.php" class="form-solid-blue" method="get">
<div class="title">
<h2></h2>
<h2>Tracking & Receiving</h2></div>
<div class="element-input<?php frmd_add_class("input2"); ?>">
<label class="title"></label>
<div class="item-cont">
<input class="small" type="text" name="store" placeholder="Store #"/>
<span class="icon-place"></span>
</div>
</div>
<div class="element-input<?php frmd_add_class("input"); ?>">
<label class="title"></label>
<div class="item-cont">
<input class="medium" type="text" name="userid" placeholder="UserId"/>
<span class="icon-place"></span>
</div>
</div>
<div class="element-input<?php frmd_add_class("input1"); ?>">
<label class="title"></label>
<div class="item-cont">
<input class="large" type="text" name="order" placeholder="Order Number"/>
<span class="icon-place"></span>
</div>
</div>
<div class="submit">
<input type="submit" value="Send"/>
</div>
<div class="element-separator">
<hr>
<h3 class="section-break-title">Tracking Numbers</h3>
</div>
<div class="element-multiple<?php frmd_add_class("multiple"); ?>">
<label class="title"></label>
<div class="item-cont">
<div class="large">
<select data-no-selected="Nothing selected" name="multiple[]" multiple="multiple">
<option value="option_1">option 1</option>
<option value="option_2">option 2</option>
<option value="option_3">option 3</option>
</select>
<span class="icon-place"></span>
</div>
</div>
</div>
<div class="submit">
<input type="submit" value="Submit"/>
</div>
</form>
This is the connection.php - Server side code
<?php
// Create connection to Oracle
$conn = oci_connect("XXXX", "xyxyx", "xyxyx");
if (!$conn) {
$m = oci_error();
echo $m['message'], "\n";
exit;
}
$query = "SELECT TRACKING_NUMBER FROM JC_SHIPPED_ORDER_TRACKING WHERE EXT_PURCHASE_ORDERS_ID = :order_bv";
$stid = oci_parse($conn, $query);
$order = $_GET['order'];
oci_bind_by_name($stid, ':order_bv', $order);
oci_execute($stid);
//Because order is a unique value I only expect one row
$row = oci_fetch_array($stid, OCI_ASSOC);
if (!$row) {
exit("The order " . $order . " is invalid. Please check and try again" );
}
$trackID = $row['TRACKING_NUMBER'];
echo "<form name=form1 method=POST action='form.php'>";
//echo "<select name='TRACKING_NUMBER' onchange=AjaxFunction();>";
while ($row = oci_fetch_array($stid)) {
echo "<option value=\"option_1\">" . $row['TRACKING_NUMBER'] . "</option>";
}
echo "</select>";
//echo ("The order " . $order . " is valid.");
oci_free_statement($stid);
oci_close($conn);
?>
This is the best I can do with the information provided.
in form.php
<select data-no-selected="Nothing selected" name="multiple[]" multiple="multiple">
<?php require 'path to connection.php'; ?>
</select>
oh and remove these from connection.php
echo "<form name=form1 method=POST action='form.php'>";
echo "</select>";
I run my php code to upload multiple file but until right now i get error like this :
PHP erorr Undefined index: link_to_doc_file_
And here is my controller :
function insert_data(){
$this->form_validation->set_rules('tool_code', 'Tool Code', 'required');
if ($this->form_validation->run()){
for($i=1;$i<=10;$i++) {
$link_to_doc_file_[$i] = (isset($_GET['link_to_doc_file_'][$i]) ? $_GET['link_to_doc_file_'][$i] : null);
$link_to_doc_file_[$i] = "";
$file_uploaded = false;
//UPLOAD DOC
if(is_uploaded_file($_FILES['link_to_doc_file_']['tmp_name'][$i])){
$folder = /*base_url() .*/ 'material/';
$ext = substr($_FILES['link_to_doc_file_']['name'][$i],strpos($_FILES['link_to_doc_file']['name'][$i],'.'));
$file_name = $this->input->post('tool_code') . (int)microtime(true) . $ext;
$target_file = $folder .$file_name;
if(!file_exists($folder))
mkdir($folder);
//if(file_exists($target_file)) unlink($target_file);
if(move_uploaded_file($_FILES['link_to_doc_file_']["tmp_name"][$i], $target_file)){
$file_uploaded = true;
$$link_to_doc_file_[$i] = $target_file;
}
}
}
$tool_code = $this->input->post($tool_code);
$data_doc = null;
//Data Description
for($i=1;$i<=10;$i++){
$data_doc['title'][$i-1] = $this->input->post('doc_title_' . $i);
$data_doc['link'][$i-1] = $this->input->post('link_to_doc_file_'.$i);
$data_doc['show'][$i-1] = $this->input->post('doc_display_' . $i);
}
$data['doc'] = $data_doc;
if($this->input->post('is_edit')){
//UPDATE
$this->model_tool->update_tool_document($this, $data);
}else{
//INSERT
$this->model_tool->insert_tool_document($this, $data);
}
redirect(MENU_TOOL_DOC);
}else{
}
}
}
Here my View :
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
<?php echo (($id)?"Edit":"Add") . " Document"; ?>
</div>
<div class="panel-body">
<?php echo form_open_multipart(base_url() . MENU_TOOL_DOC . '/insert_data');?>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<input type="hidden" name="tool_code" value="<?php echo $tool_code;?>">
<label>Tool Code : <?php echo $tool_name;?></label>
<?php
for($i=1;$i<=10;$i++){
?>
<div class="form-group">
<label>Document <?php echo $i;?></label>
<div class="form-group">
<label>Show</label>
<select class="form-control" name="doc_show_<?php echo $i;?>">
<?php
for($j=0;$j<count($show);$j++){
?>
<option value="<?php echo ($j); ?>" <?php echo (isset($row))?(($doc['show'][$i-1] == $j)?"selected":""):"";?>>
<?php echo $show[$j];?>
</option>
<?php
}
?>
</select>
</div>
<div class="form-group">
<label>Title</label>
<input class="form-control" name="doc_title_<?php echo $i;?>" value="<?php echo (isset($row))?$doc['title'][$i-1]:"";?>">
</div>
<div class="form-group form-inline">
<label>File</label>
<input type="file" name="link_to_doc_file_<?php echo $i;?>" value="<?php echo (isset($row))?$doc['link'][$i-1]:"";?>">
</div>
</div>
<?php
}
?>
</div>
<div class="col-lg-12">
<input type="hidden" name="is_edit" value="<?php echo $is_edit; ?>" />
<button type="submit" class="btn btn-primary" name="submit">Submit</button>
<button type="reset" class="btn btn-default">Reset</button>
</div>
</div>
<?php echo form_close();?>
<!-- /.row (nested) -->
</div>
<!-- /.panel-body -->
</div>
<!-- /.panel -->
</div>
<!-- /.col-lg-12 -->
if only one upload i can but if many uploads file not yet until right now.
After your ist update, you are using an incremental variable in form input name.
<input type="file" name="link_to_doc_file_<?php echo $i;?>">
Now, you are getting undefined index array because you are defining index as:
link_to_doc_file_
This should be defined as:
$_FILES['link_to_doc_file_'.$i]
More explanation:
link_to_doc_file_ != link_to_doc_file_1
Side Note:
Also check this variable $_GET['link_to_doc_file_'][$i], you need to change it also.
You're looking for $FILES['link_to_doc_file'] but you're setting it with an integer and the end:
name="link_to_doc_file_<?php echo $i;?>"
in your upload script you have to look for that same integer
if(is_uploaded_file($_FILES['link_to_doc_file_$some_integer']['tmp_name'][$i])){