php


PHP while loop fill shop


I'm currently making a personal website & forums (That'll remain personal for a while)
By posting helpful threads or answering questions frequently users will be granted "Reputation points"
The end goal is to have these "Reputation points" as a spendable currency on the site, enabling the ability to purchase entry into elite forum sections, coloured username text, etc.
But right now I'm on the basics of FILLING the shop with the products.
I'm connected to my database, and have access to the tables within it (I can print out the data contains in the rows with the following php after connection has been established):
<?php
// Fill shop
while ($row = mysqli_fetch_array($result)) {
echo $row["Product Name"]." ".$row["Price"]."<br />";
}
?>
However, what I'd like to do is integrate some html and use my item class (in CSS) for how a shop item should be formatted.
Keep in mind, that this code below doesn't work, but it's an example of what I'm trying to accomplish:
<div class="item">
<h3><?php $row["Product Name"] ?></h3>
<img src="<?php $row["ProductImagePath"]?>"/><br />
<?php $row["Product Price"] ?>
<form action="" method="post">
<input type="submit" value="Buy" />
</form>
</div>
So, instead of just listing the data, it instead places it into an item and generates a new item (one per product found)
Any idea how I'd achieve this?
Thanks, would appreciate any assistance.
To print out the items in html you can just use the same foreach you have above and print out the items by echoing out their values:
<?php
while ($row = mysqli_fetch_array($result)) {
?>
<div class="item">
<h3><?php echo $row["Product Name"] ?></h3>
<img src="<?php echo $row["ProductImagePath"]?>"/><br />
<?php echo $row["Product Price"] ?>
<form action="" method="post">
<input type="submit" value="Buy" />
</form>
</div>
<?php
}
?>
where basically what you were missiing are the actual echo statements to output the values into the html source
The code you posted is just fine except for one thing: add an echo in front of every $row[...]. Right now you are just calling the rows without echoing them.
It would look like this:
<div class="item">
<h3><?php echo $row["Product Name"]; ?></h3>
<img src="<?php echo $row["ProductImagePath"]; ?>"/><br />
<?php echo $row["Product Price"]; ?>
<form action="" method="post">
<input type="submit" value="Buy" />
</form>
</div>

Related Links

How can I get dynamically a number out of a bigger number?
$Sum function in nested document MongoDB
what is the difference between __FILE__ and $_SERVER['SCRIPT_FILENAME']?
Unable To fetch data from database to script tag while using graph
DB Table of constants vs constants in code
Htaccess look for pattern in url that end in .html and redirect
Session not working in middleware Laravel 5
convert array to word
Check if answer is correct MCQ
How should i verify cookies for username and password in HTML page
changing from mysql to mysqli standard proceedure - prepared statements?
PHP session won't show all keys after AJAX call
How to read content of socket stream in PHP stream socket server
Printing JSON (from a php) through ajax to a bootstrap modal
How to create <div> for h1,h2 and so on using DOM parser in php?
how to find page number of a website and put it in a variable [closed]

Categories

HOME
opengl
extjs
verification
apple-push-notifications
dotnetnuke
kivy
dry
risk-management
informatica
semantic-web
mongoid
gallery
openfoam
repair
haxe
ag-grid
onvif
minecraft
scheduler
timber
locationmanager
chromecast
jquery-select2-4
ex
amazon-elb
squirrel-sql
reselect
opam
angular2-highcharts
tableview
pst
substring
hdmi
bitbake
fusion
openbr
jsonresult
publishing
nest
markov-chains
gnu-classpath
amazon-kms
forms-authentication
telephonymanager
export-to-pdf
netapp
plane
react-intl
rightnow-crm
cyanogenmod
nothing
gtk#
nslayoutconstraint
polymaps
gmaps.js
pecl
dynamics-crm-4
kendo-treeview
yargs
cefpython
p6spy
wininet
qtcpsocket
groovyfx
maximize
swiffy
pack
nette
astropy
uitest
shoes
quercus
gflags
text-align
android-audiomanager
htmltidy
global-scope
osascript
meteor-collections
flipboard
principalcontext
smips
san
iirf
django-facebook
icenium
jquery-dialog
word-frequency
cakeyframeanimation
mmc3
qtextbrowser
data-dump
qt-mobility
kext
azure-acs
printqueue
activestate
android-input-method
asdoc
3270
subtext
eai
fuzzy-comparison
icon-language
gui-designer
bindable-linq

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile