Jump to content

demuro1

Members
  • Posts

    46
  • Joined

  • Last visited

About demuro1

  • Birthday 03/10/1980

Profile Information

  • Location
    A Golden State

demuro1's Achievements

Newbie

Newbie (1/7)

1

Reputation

  1. Hello, I am taking a class on sql. We are using sql server 2008 r2. We have a project to create a database and create 3 stored procedures. I have created the database as well as the entries for it. The stored procedures are giving me a little trouble though. I'd love if you could offer some help on how to fix these. Thanks so much! I have 2 that I am working on: stored procedure 1 returns these errors: here's the code:USE drOfficeDBIF EXISTS ( SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE SPECIFIC_SCHEMA = N'dbo' AND SPECIFIC_NAME = N'sp_todaysappt') DROP PROCEDURE dbo.sp_todaysapptGOCREATE PROCEDURE dbo.sp_todaysappt@date date = GETDATE()ASSELECT appointment.starttime, patient.phone, patient.patientId, patient.fname+' '+patient.minitial+' '+patient.lname as fullname, appointment.problem FROM appointment INNER JOIN patient ON appointment.patientId = patient.patientIdwhere apptdate = @dateGO-- =============================================-- Example to execute the stored procedure-- =============================================EXECUTE dbo.sp_todaysappt getdate()GO This is the error from the second stored procedure: and here's the code: IF EXISTS ( SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE SPECIFIC_SCHEMA = N'dbo' AND SPECIFIC_NAME = N'sp_patientHistory') DROP PROCEDURE dbo.sp_patientHistoryGOCREATE PROCEDURE dbo.sp_patientHistory@patientId int = patient.patientidASSELECT patient.fname + ' ' + patient.lname as full_name, appointment.apptdate, appointment.problem, diagnosis.diganosis, diagnosis.diagNotes, perscription.perscription, perscription.instructionswhere patientid = @patientId FROM appointmentINNER JOIN diagnosis ON appointment.apptId = diagnosis.apptIdINNER JOIN patient ON appointment.patientId = patient.patientIdINNER JOIN perscription ON diagnosis.diagnosisId = perscription.diagnosisIdGO-- =============================================-- Example to execute the stored procedure-- =============================================EXECUTE dbo.sp_patientHistory 1GO
  2. ok figured it out. Thanks so much for all your help!!! I ended up using a while loop and populating an array that I could index in a for loop. Again thanks so much for all of your help everyone! If you see anything I can do to make this code better please let me know! My code ended up like this: <html><!--Release InformationRelease Version 2.0.0Release Notes: -page completely rewritten to take advantage of php--><?php#initialize and declare variables#where do I send the form?$formpath = ($_SERVER['PHP_SELF']);#table attributes$border=1;$edgewidth='15%';$tablealignment='centop';$tealign='cenmid';$visibility='hidden';#error reportingerror_reporting(E_ALL);ini_set('display_errors','1');$link = mysqli_connect('127.0.0.1:3306', 'root', '4pp1353c', 'storedatabase');#check connectionif (mysqli_connect_errno()){printf("Connect failed: %s\n", mysqli_connect_error());exit();}#define array$id = array();$Product_name = array();$shape = array();$size = array();$color = array();$price = array();$numberOfItems = array();$imageFilename = array();$shortDescription = array();$fullDescription = array();#query and search$query = "SELECT * FROM inventory ORDER by id ASC";#fill array$result = mysqli_query($link, $query);$numberOfResults = $result->num_rows;$i=0;while ($row = mysqli_fetch_assoc($result)) { $id[$i] =$row['id']; $Product_name[$i] =$row['Product_name']; $shape[$i] =$row['shape']; $size[$i] =$row['size']; $color[$i] =$row['color']; $price[$i] =$row['price']; $numberOfItems[$i] =$row['numberOfItems']; $imageFilename[$i] =$row['imageFilename']; $shortDescription[$i] =$row['shortDescription']; $fullDescription[$i] =$row['fullDescription']; $i+=1; }#variables$itemsperpage = 3;$itemsperrow = 3;$rowsperpage = $itemsperpage/$itemsperrow;$numberOfPages = ceil($numberOfResults/$itemsperpage);#page number attributes$maxPage = $numberOfResults/$itemsperpage;$previousButton;$nextButton;$pageFieldDefaultValue='Jump to Page';#------------------------------------$pageNumber;if(isset($_POST['pageNumber'])){$pageNumber = $_POST['pageNumber'];}else if(!isset($pageNumber)){$pageNumber=1;}#------------------------------------if($pageNumber==1){$previousButton='=X=X=X= Page '.($pageNumber);}else{$previousButton='<==Go to Page '.($pageNumber-1);}if($pageNumber==$maxPage){$nextButton='=X=X=X= Page '.($pageNumber);}else{$nextButton='Go to Page '.($pageNumber+1).'==>';}#items per pageif(!isset($_POST['itemsperpage'])){$itemsperpage=3;}else{$itemsperpage = $_POST['itemsperpage'];}?><head> <title>Awesome Shape Store</title> <style>/*sadly this is done without style*/ .centop { text-align:center; vertical-align:top; } .cenmid { text-align:center; vertical-align:middle; } .header { font-family:"courier" text-align:center; vertical-align:top; font-size:250%; font-weight:bold; } .tiny { font-family:"courier" text-align:center; vertical-align:top; font-size:75%; font-style:italic; } </style> <script type='text/javascript'>/*make some magic*//*-========================================-*//*-- Initialization and Display Functions --*//*-========================================-*/ function onLoad() { pageNumber() } var timer = setTimer("",0); /* reset the timer for add to cart display or other messages */ function alertDisplay(d) { var time=2000; document.getElementById("div_display").innerHTML=d; clearTimeout(timer); timer=setTimeout("document.getElementById('div_display').innerHTML=''", time); }/*End Initialize and Display Functions*//*-===================-*//*-- Set hidden info --*//*-===================-*/ function invisibles() { if (document.getElementById('visibles').checked) { document.getElementById('hide1').style.visibility = 'hidden'; document.getElementById('hide2').style.visibility = 'hidden'; } else { document.getElementById('hide1').style.visibility = 'visible'; document.getElementById('hide2').style.visibility = 'visible'; } } function itemspp(sel) { var items=27; //"<?php echo $numberOfResults; ?>"; var itemsperpage = sel.options[sel.selectedIndex].value; //alert(itemsperpage); if (items%itemsperpage != 0) {document.getElementById('nop').innerHTML = (Math.floor(items/itemsperpage)+1);} else {document.getElementById('nop').innerHTML = (items/itemsperpage);} form.submit(); }/*-====================-*//*-- Action Functions --*//*-====================-*/ //when you add the php to this button id will be named with a php variable and the variable will be the item id var cart = new Array(); function addToCart(input,form) { var i=parseInt(input.id); if (typeof cart[i] !== 'undefined' && cart[i] != null) {cart[i] += 1;} else {cart[i] = 1;} alert(input.id + " is in your cart "+cart[i]+' times'); var itemName = input.id + "pn" alertDisplay('A ' + document.getElementById(itemName).innerHTML + ' has been added to your cart'); } function search(input,form) { //alert('You Searched for: ' + document.getElementById('searchField').value); form.submit(); } /*==-Page Number Function-==*/ function pageNumber(input,form) { //alert('You selected ' + input.id); var maxPage = <?php echo $maxPage; ?>; var p = parseInt(document.getElementById('pageNumber').value); //input.id is numberField if ((input.id == 'pageField') && ( (isNaN(document.getElementById('pageField').value)) || (parseFloat(document.getElementById('pageField').value) % 1 !== 0) || (parseInt(document.getElementById('pageField').value) < 1) || (parseInt(document.getElementById('pageField').value) > <?php echo $maxPage; ?>) )) { alert('I\'m Sorry, ' + document.getElementById('pageField').value + '\ is not a valid page number. \nYou will be returned to page ' + document.getElementById('pageNumber').value); } else if (input.id == 'pageField') { document.getElementById('pageNumber').value = parseInt(document.getElementById('pageField').value); }//input.id is previousPage else if (input.id == 'previousPage' && p <= 1) { alertDisplay('You are already on page ' + p); return; } else if (input.id == 'previousPage') { p -= 1; document.getElementById('pageNumber').value = p; }//input.id is nextPage else if (input.id == 'nextPage' && p >= <?php echo $maxPage; ?>) { alertDisplay('You are on the last page.'); return; } else if (input.id == 'nextPage') { p += 1; document.getElementById('pageNumber').value = p; } else {alert('pageNumber Error');} form.submit(); } /*-===================================-*//*-- Button and Keystroke Submission --*//*-===================================-*/ function buttonSubmit(button,form) { if (button.id == 'searchButton') { search(button,form); } else if (button.id == 'previousPage' || button.id == 'nextPage') { pageNumber(button,form); } else if (button.name == 'addToCart') { //alert(button.name); addToCart(button,form); } else { alert('button click error'); alert(button.id); alert(form.name); } } function keystrokeSubmit(textbox,e,form) { e = e? e : window.event; var prskeyrtrn = e.keyCode? e.keyCode : e.which? e.which : e.charCode? e.charCode :null; if (prskeyrtrn == 13 && textbox.id == 'searchField') { search(textbox,form); } else if (prskeyrtrn == 13 && textbox.id == 'pageField') { pageNumber(textbox,form); } else{} } </script></head> <body onLoad="onLoad()"><!--=====================--><!--==begin top of page==--><!--=====================--><form name="headForm" id="headForm" method="POST" action="<?php echo $formpath; ?>"> <table width="100%" class="<?php echo $tablealignment; ?>" border="<?php echo $border; ?>"> <tr class="<?php echo $tealign; ?>"><!--left side of head --> <td width="<?php echo $edgewidth; ?>"> <table height="90" border="<?php echo $border; ?>" class="<?php echo $tablealignment; ?>" width="100%"> <tr class="<?php echo $tealign; ?>"><td><div name="pagediv" id="pagediv">Current Page: <?php echo $pageNumber; ?></div></td></tr> <tr class="<?php echo $tealign; ?>"><td><input type="text" id="pageField" name="pageField" placeholder="<?php echo $pageFieldDefaultValue; ?>" onkeypress="keystrokeSubmit(this,event,form)"></td></tr> <tr class="<?php echo $tealign; ?>"><td><input style="cursor:pointer" type="button" id="previousPage" name="previousPage" value="<?php echo $previousButton; ?>" onclick="buttonSubmit(this,form);"></td></tr> </table> </td><!--center of head --> <td class="<?php echo $tealign; ?>" width="80%"> <table height="90" border="<?php echo $border; ?>" class="<?php echo $tablealignment; ?>" width="100%"> <tr class="header"><td height="10%">Awesome Shape Store Catalog</td></tr> <tr class="<?php echo $tealign; ?>"><td height="90%"><div id="div_display" class="centop"></div></td></tr> </table> </td><!--right side of head --> <td width="<?php echo $edgewidth; ?>"> <table height="90" border="<?php echo $border; ?>" class="<?php echo $tablealignment; ?>" width="100%"> <tr class="<?php echo $tealign; ?>"><td><input type="text" id="searchField" name="searchField" placeholder="Search" onkeypress="keystrokeSubmit(this,event,form)"></td></tr> <tr class="<?php echo $tealign; ?>"><td><input style="cursor:pointer" type="button" id="searchButton" name="searchButton" value="Awesome Search" onclick="buttonSubmit(this,form);"></td></tr> <tr class="<?php echo $tealign; ?>"><td><input style="cursor:pointer" type="button" id="nextPage" name="nextPage" value="<?php echo $nextButton; ?>" onclick="buttonSubmit(this,form);"></td></tr> </table> </td> </tr> </table><!--This is an invisible table and it holds the pageNumber--> <table class="tiny" border="<?php echo $border; ?>"> <tr> <td> Page Display Attributes: </td> <td colspan="2"> <input type="checkbox" checked name="visibles" id="visibles" value="show invisibles" onclick="invisibles();"> </td> </tr> <tr style="visibility:hidden" name="hideFields" id="hide1"> <td>Current page number</td> <td>Items per page:</td> <td>Number of pages:</td> </tr> <tr style="visibility:hidden" name="hideFields"id="hide2"> <td><input type="text" id="pageNumber" name="pageNumber" value="<?php echo $pageNumber; ?>"></td> <td> <?php echo $itemsperpage; ?><!-- <select id="itemsperpage" name="itemsperpage" onchange="itemspp(this);"> <option value="1">1 item</option> <option value="3" selected="selected">3 items</option> <option value="6">6 items</option> <option value="9">9 items</option> <option value="18">18 items</option> <option value="27">all items</option> </select>--> </td> <td><div name="nop" id="nop"><?php echo $numberOfPages; ?></div></td> </tr> </table></form><!--===================--><!--==end top of page==--><!--===================--> <!--===== This is a seperator ========== This is a seperator ========== This is a seperator =====--><!--===== This is a seperator ========== This is a seperator ========== This is a seperator =====--><!--===== This is a seperator ========== This is a seperator ========== This is a seperator =====--> <!--==============================--><!--==begin main section of page==--><!--==============================--><div name="divbody' id="divbody"> <table> <?php echo "<tr>"; for ($r=(($pageNumber-1)*3); $r<=((($pageNumber-1)*3)+2); $r++) { echo" <td> <table> <tr> <!--catalog image--> <td valign='top'><img src='http://localhost/phpTestCode/web%20apps%20labs/Lab%2010/".$imageFilename[$r]."'></td> <td><table> <tr> <!--catalog id--> <td valign='top'><b>Item ID:</b></td> <td>".$id[$r]."</td> </tr> <tr> <!--catalog name--> <td valign='top'><b>Item Name:</b></td> <td id='".$id[$r]."pn'>".$Product_name[$r]."</td> </tr> <tr> <!--catalog shape--> <td valign='top'><b>Shape:</b></td> <td>".$shape[$r]."</td> </tr> <tr> <!--catalog size--> <td valign='top'><b>Size:</b></td> <td>".$size[$r]."</td> </tr> <tr> <!--catalog color--> <td valign='top'><b>Color:</b></td> <td><font color=".$color[$r].">".$color[$r]."</td> </tr> <tr> <!--catalog price--> <td valign='top'><b>Price:</b></td> <td>$".$price[$r]."</td> </tr> <tr> <!--catalog description--> <td valign='top'><b>Description:</b></td> <td> This is an amazing".$size[$r]." <font color=".$color[$r]."><b>".$color[$r]."</b></font> ".$shape[$r]." with a super cool black border</td> </tr> </table></td> </tr> <!--add to cart button--> <!--id set by php--> <!--<form name='addToCart' method='POST'action=". $formpath ."'>--> <tr><td><input type='button' value='Add to Cart' name='addToCart' id='".$id[$r]."' onclick='buttonSubmit(this,form);'></td></tr> <!--</form>--> </table> </td> "; } echo "</tr>"; ?> </table></div><!--============================--><!--==end main section of page==--><!--============================--></body></html>
  3. niche, thanks for the help, I don't know how to do what you're suggesting though I'm sorry justsomeguyYou're right, I forgot to post the errors. I get these two errors Warning: mysql_query() expects parameter 1 to be string, object given in /Library/WebServer/Documents/phpTestCode/web apps labs/Lab 10/catalogBeta2.php on line 386Warning: mysql_fetch_assoc() expects parameter 1 to be resource, null given in /Library/WebServer/Documents/phpTestCode/web apps labs/Lab 10/catalogBeta2.php on line 388
  4. I have confirmed that the correct functions are being called. and nothing happens. The add to cart button may as well not be connected to anything. when I take out the array in the add to cart function suddenly everything works fine but I need the array to work.
  5. hello. i am working on a term project and it's almost done. I am making a shopping cart and I am working on an add to cart function. I am using an array to capture element id and using that as the index of the array element. I am incrementing the element with every click of the add to cart button. It works in the is simple script but not in the larger one. Can anyone offer any suggestions on how to fix this? Thanks so much This code works: <!DOCTYPE html><html><head><script>var cart = new Array(); function addToCart(input,form){ var i=parseInt(input.id); if (typeof cart[i] !== 'undefined' && cart[i] != null) {cart[i] += 1;} else {cart[i] = 1;} alert(input.id + " is in your cart "+cart[i]+' times'); }</script></head><body><table> <tr> <td><input type="button" id="0" value="turkey" onclick="addToCart(this);"></td> <td><input type="button" id="1" value="goose" onclick="addToCart(this);"></td> <td><input type="button" id="2" value="duck" onclick="addToCart(this);"></td> </tr></table></body></html> The trouble section is the add to cart javascript function. It doesn't work here and I just copied and pasted the code. <html><!--Release Information Release Version 2.0.0Release Notes: -page completely rewritten to take advantage of php--><?php#initialize and declare variables#where do I send the form?$formpath = ($_SERVER['PHP_SELF']);#table attributes$border=1;$edgewidth='15%';$tablealignment='centop';$tealign='cenmid';$visibility='hidden';#error reportingerror_reporting(E_ALL);ini_set('display_errors','1');$link = mysqli_connect('127.0.0.1:3306', 'root', '4pp1353c', 'storedatabase');#check connectionif (mysqli_connect_errno()){printf("Connect failed: %s\n", mysqli_connect_error());exit();}#query string and search$query = "SELECT * FROM inventory ORDER by id ASC";$result = mysqli_query($link, $query);$queryReturn = $result->num_rows; #variables$itemsperpage = 3;$itemsperrow = 3;$rowsperpage = $itemsperpage/$itemsperrow; #page number attributes$maxPage = $queryReturn/$itemsperpage;$previousButton;$nextButton;$pageFieldDefaultValue='Jump to Page';#------------------------------------$pageNumber;if(isset($_POST['pageNumber'])){$pageNumber = $_POST['pageNumber'];}else if(!isset($pageNumber)){$pageNumber=1;} #------------------------------------if($pageNumber==1){$previousButton='=X=X=X= Page '.($pageNumber);}else{$previousButton='<==Go to Page '.($pageNumber-1);}if($pageNumber==$maxPage){$nextButton='=X=X=X= Page '.($pageNumber);}else{$nextButton='Go to Page '.($pageNumber+1).'==>';} #items per pageif(!isset($_POST['itemsperpage'])){$itemsperpage=3;}else{$itemsperpage = $_POST['itemsperpage'];} ?> <head> <title>Awesome Shape Store</title> <style>/*sadly this is done without style*/ .centop { text-align:center; vertical-align:top; } .cenmid { text-align:center; vertical-align:middle; } .header { font-family:"courier" text-align:center; vertical-align:top; font-size:250%; font-weight:bold; } .tiny { font-family:"courier" text-align:center; vertical-align:top; font-size:75%; font-style:italic; } </style> <script type='text/javascript'>/*make some magic*/ /*-========================================-*//*-- Initialization and Display Functions --*//*-========================================-*/ function onLoad() { pageNumber() } var timer = setTimer("",0); /* reset the timer for add to cart display or other messages */ function alertDisplay(d) { var time=2000; document.getElementById("div_display").innerHTML=d; clearTimeout(timer); timer=setTimeout("document.getElementById('div_display').innerHTML=''", time); }/*End Initialize and Display Functions*//*-===================-*//*-- Set hidden info --*//*-===================-*/ function invisibles() { if (document.getElementById('visibles').checked) { document.getElementById('hide1').style.visibility = 'hidden'; document.getElementById('hide2').style.visibility = 'hidden'; } else { document.getElementById('hide1').style.visibility = 'visible'; document.getElementById('hide2').style.visibility = 'visible'; } } function itemspp(sel) { var items=27; //"<?php echo $queryReturn; ?>"; var itemsperpage = sel.options[sel.selectedIndex].value; //alert(itemsperpage); if (items%itemsperpage != 0) {document.getElementById('nop').innerHTML = (Math.floor(items/itemsperpage)+1);} else {document.getElementById('nop').innerHTML = (items/itemsperpage);} form.submit(); }/*-====================-*//*-- Action Functions --*//*-====================-*/ //when you add the php to this button id will be named with a php variable and the variable will be the item id var cart = new Array(); function addToCart(input,form) { var i=parseInt(input.id); if (typeof cart[i] !== 'undefined' && cart[i] != null) {cart[i] += 1;} else {cart[i] = 1;} alert(input.id + " is in your cart "+cart[i]+' times'); var itemName = input.id + "pn" alertDisplay('A ' + document.getElementById(itemName).innerHTML + ' has been added to your cart'); } function search(input,form) { //alert('You Searched for: ' + document.getElementById('searchField').value); form.submit(); } /*==-Page Number Function-==*/ function pageNumber(input,form) { //alert('You selected ' + input.id); var maxPage = <?php echo $maxPage; ?>; var p = parseInt(document.getElementById('pageNumber').value); //input.id is numberField if ((input.id == 'pageField') && ( (isNaN(document.getElementById('pageField').value)) || (parseFloat(document.getElementById('pageField').value) % 1 !== 0) || (parseInt(document.getElementById('pageField').value) < 1) || (parseInt(document.getElementById('pageField').value) > <?php echo $maxPage; ?>) )) { alert('I\'m Sorry, ' + document.getElementById('pageField').value + '\ is not a valid page number. \nYou will be returned to page ' + document.getElementById('pageNumber').value); } else if (input.id == 'pageField') { document.getElementById('pageNumber').value = parseInt(document.getElementById('pageField').value); }//input.id is previousPage else if (input.id == 'previousPage' && p <= 1) { alertDisplay('You are already on page ' + p); return; } else if (input.id == 'previousPage') { p -= 1; document.getElementById('pageNumber').value = p; }//input.id is nextPage else if (input.id == 'nextPage' && p >= <?php echo $maxPage; ?>) { alertDisplay('You are on the last page.'); return; } else if (input.id == 'nextPage') { p += 1; document.getElementById('pageNumber').value = p; } else {alert('pageNumber Error');} form.submit(); } /*-===================================-*//*-- Button and Keystroke Submission --*//*-===================================-*/ function buttonSubmit(button,form) { if (button.id == 'searchButton') { search(button,form); } else if (button.id == 'previousPage' || button.id == 'nextPage') { pageNumber(button,form); } else if (button.name == 'addToCart') { //alert(button.name); addToCart(button,form); } else { alert('button click error'); alert(button.id); alert(form.name); } } function keystrokeSubmit(textbox,e,form) { e = e? e : window.event; var prskeyrtrn = e.keyCode? e.keyCode : e.which? e.which : e.charCode? e.charCode :null; if (prskeyrtrn == 13 && textbox.id == 'searchField') { search(textbox,form); } else if (prskeyrtrn == 13 && textbox.id == 'pageField') { pageNumber(textbox,form); } else{} } </script></head> <body onLoad="onLoad()"><!--=====================--><!--==begin top of page==--><!--=====================--><form name="headForm" id="headForm" method="POST" action="<?php echo $formpath; ?>"> <table width="100%" class="<?php echo $tablealignment; ?>" border="<?php echo $border; ?>"> <tr class="<?php echo $tealign; ?>"><!--left side of head --> <td width="<?php echo $edgewidth; ?>"> <table height="90" border="<?php echo $border; ?>" class="<?php echo $tablealignment; ?>" width="100%"> <tr class="<?php echo $tealign; ?>"><td><div name="pagediv" id="pagediv">Current Page: <?php echo $pageNumber; ?></div></td></tr> <tr class="<?php echo $tealign; ?>"><td><input type="text" id="pageField" name="pageField" placeholder="<?php echo $pageFieldDefaultValue; ?>" onkeypress="keystrokeSubmit(this,event,form)"></td></tr> <tr class="<?php echo $tealign; ?>"><td><input style="cursor:pointer" type="button" id="previousPage" name="previousPage" value="<?php echo $previousButton; ?>" onclick="buttonSubmit(this,form);"></td></tr> </table> </td><!--center of head --> <td class="<?php echo $tealign; ?>" width="80%"> <table height="90" border="<?php echo $border; ?>" class="<?php echo $tablealignment; ?>" width="100%"> <tr class="header"><td height="10%">Awesome Shape Store Catalog</td></tr> <tr class="<?php echo $tealign; ?>"><td height="90%"><div id="div_display" class="centop"></div></td></tr> </table> </td><!--right side of head --> <td width="<?php echo $edgewidth; ?>"> <table height="90" border="<?php echo $border; ?>" class="<?php echo $tablealignment; ?>" width="100%"> <tr class="<?php echo $tealign; ?>"><td><input type="text" id="searchField" name="searchField" placeholder="Search" onkeypress="keystrokeSubmit(this,event,form)"></td></tr> <tr class="<?php echo $tealign; ?>"><td><input style="cursor:pointer" type="button" id="searchButton" name="searchButton" value="Awesome Search" onclick="buttonSubmit(this,form);"></td></tr> <tr class="<?php echo $tealign; ?>"><td><input style="cursor:pointer" type="button" id="nextPage" name="nextPage" value="<?php echo $nextButton; ?>" onclick="buttonSubmit(this,form);"></td></tr> </table> </td> </tr> </table><!--This is an invisible table and it holds the pageNumber--> <table class="tiny" border="<?php echo $border; ?>"> <tr> <td> Page Display Attributes: </td> <td colspan="2"> <input type="checkbox" checked name="visibles" id="visibles" value="show invisibles" onclick="invisibles();"> </td> </tr> <tr style="visibility:hidden" name="hideFields" id="hide1"> <td>Current page number</td> <td>Items per page:</td> <td>Number of pages:</td> </tr> <tr style="visibility:hidden" name="hideFields"id="hide2"> <td><input type="text" id="pageNumber" name="pageNumber" value="<?php echo $pageNumber; ?>"></td> <td> <?php echo $itemsperpage; ?><!-- <select id="itemsperpage" name="itemsperpage" onchange="itemspp(this);"> <option value="1">1 item</option> <option value="3" selected="selected">3 items</option> <option value="6">6 items</option> <option value="9">9 items</option> <option value="18">18 items</option> <option value="27">all items</option> </select>--> </td> <td><div name="nop" id="nop">9</div></td> </tr> </table></form> <!--===================--><!--==end top of page==--><!--===================--> <!--===== This is a seperator ========== This is a seperator ========== This is a seperator =====--><!--===== This is a seperator ========== This is a seperator ========== This is a seperator =====--><!--===== This is a seperator ========== This is a seperator ========== This is a seperator =====--> <!--==============================--><!--==begin main section of page==--><!--==============================--><div name="divbody' id="divbody"> <table> <?php/* for ($r=0; $r<=$rowsperpage-1; $r++) {*/ echo "<tr>"; for ($i=1; $i<=$itemsperrow; $i++) { $query = "SELECT * FROM inventory Where id =".($i+($pageNumber-1)*3)." ORDER by id ASC"; $result = mysqli_query($link, $query); $row = mysqli_fetch_assoc($result); print ( "<td> <table> <tr> <!--catalog image--> <td valign='top'><img src='http://localhost/phpTestCode/web%20apps%20labs/Lab%2010/".$row["imageFilename"]."'></td> <td><table> <tr> <!--catalog id--> <td valign='top'><b>Item ID:</b></td> <td>".$row["id"]."</td> </tr> <tr> <!--catalog name--> <td valign='top'><b>Item Name:</b></td> <td id='".$row['id']."pn'>".$row["Product_name"]."</td> </tr> <tr> <!--catalog shape--> <td valign='top'><b>Shape:</b></td> <td>".$row["shape"]."</td> </tr> <tr> <!--catalog size--> <td valign='top'><b>Size:</b></td> <td>".$row["size"]."</td> </tr> <tr> <!--catalog color--> <td valign='top'><b>Color:</b></td> <td><font color=".$row['color'].">".$row["color"]."</td> </tr> <tr> <!--catalog price--> <td valign='top'><b>Price:</b></td> <td>$".$row["price"]."</td> </tr> <tr> <!--catalog description--> <td valign='top'><b>Description:</b></td> <td> This is an amazing".$row["size"]." <font color=".$row["color"]."><b>".$row["color"]."</b></font> ".$row["shape"]." with a super cool black border</td> </tr> </table></td> </tr> <!--add to cart button--> <!--id set by php--> <!--<form name='addToCart' method='POST'action=". $formpath ."'>--> <tr><td><input type='button' value='Add to Cart' name='addToCart' id='".$row["id"]."' onclick='buttonSubmit(this,form);'></td></tr> <!--</form>--> </table> </td>" ); } echo "</tr>";/* }*/ ?> </table></div><!--============================--><!--==end main section of page==--><!--============================--></body></html>
  6. I tried a select tag in a form. When I used the onchange event with it and directed it to a function with form.submit() it didn't post. The onchnage would work to alter value in javascript but I couldn't get it to post. If you figure it out let me know. Good luck.
  7. I have been working on this project all semester and it's almost due. It is a catalog. I need help or suggestions on how to structure this query and a loop to display everything. I previous had this working and I used a for loop to iterate through everything. Now I need to account for a search by the user. So here is what I need help with: I need to structure a query that will return only 3 results per pagefor example on page load-the query returns the entry database-page 1 loads and returns 1,2,3-the user click the next page button-page 2 will load and return items 4,5,6 etc if I run a query and it return results 2,5,7,9,12,14,18,19,27 -page 1 loads and returns items 2,5,7 -the user click the next page button-page 2 will load and return items 9,12,14etc I am kind of desperate for help! I have a query statement at the top of the page to count how many items are returned, this feeds the javascript how many page the catalog will generate I have a query statement in the body of the page that feeds the loop. I assume there is a ways to combine this stuff but I can't get the query to work. <html><!--Release InformationRelease Version 2.0.0Release Notes: -page completely rewritten to take advantage of php--><?php#initialize and declare variables#where do I send the form?$formpath = ($_SERVER['PHP_SELF']);#table attributes$border=1;$edgewidth='15%';$tablealignment='centop';$tealign='cenmid';$visibility='hidden';#error reportingerror_reporting(E_ALL);ini_set('display_errors','1');$link = mysqli_connect('127.0.0.1:3306', 'root', '4pp1353c', 'storedatabase');#check connectionif (mysqli_connect_errno()){printf("Connect failed: %s\n", mysqli_connect_error());exit();}#query string and search$query = "SELECT * FROM inventory ORDER by id ASC";$result = mysqli_query($link, $query);$queryReturn = $result->num_rows;#variables$itemsperpage = 3;$itemsperrow = 3;$rowsperpage = $itemsperpage/$itemsperrow;#page number attributes$maxPage = $queryReturn/$itemsperpage;$previousButton;$nextButton;$pageFieldDefaultValue='Jump to Page';#------------------------------------$pageNumber;if(isset($_POST['pageNumber'])){$pageNumber = $_POST['pageNumber'];}else if(!isset($pageNumber)){$pageNumber=1;}#------------------------------------if($pageNumber==1){$previousButton='=X=X=X= Page '.($pageNumber);}else{$previousButton='<==Go to Page '.($pageNumber-1);}if($pageNumber==$maxPage){$nextButton='=X=X=X= Page '.($pageNumber);}else{$nextButton='Go to Page '.($pageNumber+1).'==>';}#items per pageif(!isset($_POST['itemsperpage'])){$itemsperpage=3;}else{$itemsperpage = $_POST['itemsperpage'];}?><head> <title>Awesome Shape Store</title> <style>/*sadly this is done without style*/ .centop { text-align:center; vertical-align:top; } .cenmid { text-align:center; vertical-align:middle; } .header { font-family:"courier" text-align:center; vertical-align:top; font-size:250%; font-weight:bold; } .tiny { font-family:"courier" text-align:center; vertical-align:top; font-size:75%; font-style:italic; } </style> <script type='text/javascript'>/*make some magic*//*-========================================-*//*-- Initialization and Display Functions --*//*-========================================-*/ function onLoad() { pageNumber() } var timer = setTimer("",0); /* reset the timer for add to cart display or other messages */ function alertDisplay(d) { var time=2000; document.getElementById("div_display").innerHTML=d; clearTimeout(timer); timer=setTimeout("document.getElementById('div_display').innerHTML=''", time); }/*End Initialize and Display Functions*//*-===================-*//*-- Set hidden info --*//*-===================-*/ function invisibles() { if (document.getElementById('visibles').checked) { document.getElementById('hide1').style.visibility = 'hidden'; document.getElementById('hide2').style.visibility = 'hidden'; } else { document.getElementById('hide1').style.visibility = 'visible'; document.getElementById('hide2').style.visibility = 'visible'; } } function itemspp(sel) { var items=27; //"<?php echo $queryReturn; ?>"; var itemsperpage = sel.options[sel.selectedIndex].value; //alert(itemsperpage); if (items%itemsperpage != 0) {document.getElementById('nop').innerHTML = (Math.floor(items/itemsperpage)+1);} else {document.getElementById('nop').innerHTML = (items/itemsperpage);} form.submit(); }/*-====================-*//*-- Action Functions --*//*-====================-*/ //when you add the php to this button id will be named with a php variable and the variable will be the item id function addToCart(input,form) { alertDisplay('A' + input.id + ' added to cart'); //make an array-store the product id //if id is added to cart again increment id //array will store id and quantity } function search(input,form) { //alert('You Searched for: ' + document.getElementById('searchField').value); form.submit(); } /*==-Page Number Function-==*/ function pageNumber(input,form) { //alert('You selected ' + input.id); var maxPage = <?php echo $maxPage; ?>; var p = parseInt(document.getElementById('pageNumber').value); //input.id is numberField if ((input.id == 'pageField') && ( (isNaN(document.getElementById('pageField').value)) || (parseFloat(document.getElementById('pageField').value) % 1 !== 0) || (parseInt(document.getElementById('pageField').value) < 1) || (parseInt(document.getElementById('pageField').value) > <?php echo $maxPage; ?>) )) { alert('I\'m Sorry, ' + document.getElementById('pageField').value + '\ is not a valid page number. \nYou will be returned to page ' + document.getElementById('pageNumber').value); } else if (input.id == 'pageField') { document.getElementById('pageNumber').value = parseInt(document.getElementById('pageField').value); }//input.id is previousPage else if (input.id == 'previousPage' && p <= 1) { alertDisplay('You are already on page ' + p); return; } else if (input.id == 'previousPage') { p -= 1; document.getElementById('pageNumber').value = p; }//input.id is nextPage else if (input.id == 'nextPage' && p >= <?php echo $maxPage; ?>) { alertDisplay('You are on the last page.'); return; } else if (input.id == 'nextPage') { p += 1; document.getElementById('pageNumber').value = p; } else {alert('pageNumber Error');} form.submit(); } /*-===================================-*//*-- Button and Keystroke Submission --*//*-===================================-*/ function buttonSubmit(button,form) { if (button.id == 'searchButton') { search(button,form); } else if (button.id == 'previousPage' || button.id == 'nextPage') { pageNumber(button,form); } else if (button.name == 'addToCart') { //alert(button.name); addToCart(button,form); } else { alert('button click error'); alert(button.id); alert(form.name); } } function keystrokeSubmit(textbox,e,form) { e = e? e : window.event; var prskeyrtrn = e.keyCode? e.keyCode : e.which? e.which : e.charCode? e.charCode :null; if (prskeyrtrn == 13 && textbox.id == 'searchField') { search(textbox,form); } else if (prskeyrtrn == 13 && textbox.id == 'pageField') { pageNumber(textbox,form); } else{} } </script></head> <body onLoad="onLoad()"><!--=====================--><!--==begin top of page==--><!--=====================--><form name="headForm" id="headForm" method="POST" action="<?php echo $formpath; ?>"> <table width="100%" class="<?php echo $tablealignment; ?>" border="<?php echo $border; ?>"> <tr class="<?php echo $tealign; ?>"><!--left side of head --> <td width="<?php echo $edgewidth; ?>"> <table height="90" border="<?php echo $border; ?>" class="<?php echo $tablealignment; ?>" width="100%"> <tr class="<?php echo $tealign; ?>"><td><div name="pagediv" id="pagediv">Current Page: <?php echo $pageNumber; ?></div></td></tr> <tr class="<?php echo $tealign; ?>"><td><input type="text" id="pageField" name="pageField" placeholder="<?php echo $pageFieldDefaultValue; ?>" onkeypress="keystrokeSubmit(this,event,form)"></td></tr> <tr class="<?php echo $tealign; ?>"><td><input style="cursor:pointer" type="button" id="previousPage" name="previousPage" value="<?php echo $previousButton; ?>" onclick="buttonSubmit(this,form);"></td></tr> </table> </td><!--center of head --> <td class="<?php echo $tealign; ?>" width="80%"> <table height="90" border="<?php echo $border; ?>" class="<?php echo $tablealignment; ?>" width="100%"> <tr class="header"><td height="10%">Awesome Shape Store Catalog</td></tr> <tr class="<?php echo $tealign; ?>"><td height="90%"><div id="div_display" class="centop"></div></td></tr> </table> </td><!--right side of head --> <td width="<?php echo $edgewidth; ?>"> <table height="90" border="<?php echo $border; ?>" class="<?php echo $tablealignment; ?>" width="100%"> <tr class="<?php echo $tealign; ?>"><td><input type="text" id="searchField" name="searchField" placeholder="Search" onkeypress="keystrokeSubmit(this,event,form)"></td></tr> <tr class="<?php echo $tealign; ?>"><td><input style="cursor:pointer" type="button" id="searchButton" name="searchButton" value="Awesome Search" onclick="buttonSubmit(this,form);"></td></tr> <tr class="<?php echo $tealign; ?>"><td><input style="cursor:pointer" type="button" id="nextPage" name="nextPage" value="<?php echo $nextButton; ?>" onclick="buttonSubmit(this,form);"></td></tr> </table> </td> </tr> </table><!--This is an invisible table and it holds the pageNumber--> <table class="tiny" border="<?php echo $border; ?>"> <tr> <td> Page Display Attributes: </td> <td colspan="2"> <input type="checkbox" checked name="visibles" id="visibles" value="show invisibles" onclick="invisibles();"> </td> </tr> <tr style="visibility:hidden" name="hideFields" id="hide1"> <td>Current page number</td> <td>Items per page:</td> <td>Number of pages:</td> </tr> <tr style="visibility:hidden" name="hideFields"id="hide2"> <td><input type="text" id="pageNumber" name="pageNumber" value="<?php echo $pageNumber; ?>"></td> <td> <?php echo $itemsperpage; ?><!-- <select id="itemsperpage" name="itemsperpage" onchange="itemspp(this);"> <option value="1">1 item</option> <option value="3" selected="selected">3 items</option> <option value="6">6 items</option> <option value="9">9 items</option> <option value="18">18 items</option> <option value="27">all items</option> </select>--> </td> <td><div name="nop" id="nop">9</div></td> </tr> </table></form><!--===================--><!--==end top of page==--><!--===================--> <!--===== This is a seperator ========== This is a seperator ========== This is a seperator =====--><!--===== This is a seperator ========== This is a seperator ========== This is a seperator =====--><!--===== This is a seperator ========== This is a seperator ========== This is a seperator =====--> <!--==============================--><!--==begin main section of page==--><!--==============================--><div name="divbody' id="divbody"> <table> <tr> <?php $query = "SELECT * FROM inventory order by id limit ".(($pageNumber-1)*3).",3"; $result = mysqli_query($link, $query); while($row = mysql_fetch_assoc($result)) { print ( "<td> <table> <tr> <!--catalog image--> <td valign='top'><img src='http://localhost/phpTestCode/web%20apps%20labs/Lab%2010/".$row["imageFilename"]."'></td> <td><table> <tr> <!--catalog id--> <td valign='top'><b>Item ID:</b></td> <td>".$row["id"]."</td> </tr> <tr> <!--catalog name--> <td valign='top'><b>Item Name:</b></td> <td>".$row["Product_name"]."</td> </tr> <tr> <!--catalog shape--> <td valign='top'><b>Shape:</b></td> <td>".$row["shape"]."</td> </tr> <tr> <!--catalog size--> <td valign='top'><b>Size:</b></td> <td>".$row["size"]."</td> </tr> <tr> <!--catalog color--> <td valign='top'><b>Color:</b></td> <td><font color=".$row['color'].">".$row["color"]."</td> </tr> <tr> <!--catalog price--> <td valign='top'><b>Price:</b></td> <td>$".$row["price"]."</td> </tr> <tr> <!--catalog description--> <td valign='top'><b>Description:</b></td> <td> This is an amazing".$row["size"]." <font color=".$row["color"]."><b>".$row["color"]."</b></font> ".$row["shape"]." with a super cool black border</td> </tr> </table></td> </tr> <!--add to cart button--> <!--id set by php--> <!--<form name='addToCart' method='POST'action=". $formpath ."'>--> <tr><td><input type='button' value='Add to Cart' name='addToCart' id='".$row["Product_name"]."' onclick='buttonSubmit(this,form);'></td></tr> <!--</form>--> </table> </td>" ); } ?> </tr> </table></div><!--============================--><!--==end main section of page==--><!--============================--></body></html> Thanks so much and here is my code
  8. demuro1

    Undefined index

    I am getting an error. I believe it may be because of the select I have. The POST in that line is from the only select statement I have on the page. do you have any suggestions for fixing this. Thanks This is my error message: This is my code:<html><!--Release InformationRelease Version 2.0.0Release Notes: -page completely rewritten to take advantage of php--><?php#initialize and declare variables#where do I send the form?$formpath = ($_SERVER['PHP_SELF']);#table attributes$border=1;$edgewidth='15%';$tablealignment='centop';$tealign='cenmid';$visibility='hidden';#error reportingerror_reporting(E_ALL);ini_set('display_errors','1');$link = mysqli_connect('127.0.0.1:3306', 'root', '4pp1353c', 'storedatabase');#check connectionif (mysqli_connect_errno()){printf("Connect failed: %s\n", mysqli_connect_error());exit();}#query string$query = "SELECT * FROM inventory ORDER by id ASC";$result = mysqli_query($link, $query);$row = mysqli_fetch_row($result);#variables$itemsperpage = $result->num_rows;$itemsperrow=3;$rowsperpage=$itemsperpage/$itemsperrow;#page number attributes$maxPage = 9;$previousButton;$nextButton;$pageFieldDefaultValue='Jump to Page';#------------------------------------if(!isset($pageNumber)){$pageNumber=1;}else{$pageNumber = $_POST['pageNumber'];}#------------------------------------if($pageNumber==1){$previousButton='=X=X=X= Page '.($pageNumber);}else{$previousButton='<==Go to Page '.($pageNumber-1);}if($pageNumber==$maxPage){$nextButton='=X=X=X= Page '.($pageNumber);}else{$nextButton='Go to Page '.($pageNumber+1).'==>';}#search field attributes$searchButton='Awesome Search' ;$searchFieldDefaultValue='Search'; if(!isset($searchField)){$searchField='';}else{$searchField = $_POST['searchField'];}#items per pageif(!isset($itemsperpage)){$itemsperpage=3;}else{$itemsperpage = $_POST['itemsperpage'];}?><head> <title>Awesome Shape Store</title> <style>/*sadly this is done without style*/ .centop { text-align:center; vertical-align:top; } .cenmid { text-align:center; vertical-align:middle; } .header { font-family:"courier" text-align:center; vertical-align:top; font-size:250%; font-weight:bold; } .tiny { font-family:"courier" text-align:center; vertical-align:top; font-size:75%; font-style:italic; } </style> <script type='text/javascript'>/*make some magic*//*-========================================-*//*-- Initialization and Display Functions --*//*-========================================-*/ function onLoad() { pageNumber() } var timer = setTimer("",0); /* reset the timer for add to cart display or other messages */ function alertDisplay(d) { var time=2000; document.getElementById("div_display").innerHTML=d; clearTimeout(timer); timer=setTimeout("document.getElementById('div_display').innerHTML=''", time); }/*End Initialize and Display Functions*//*-===================-*//*-- Set hidden info --*//*-===================-*/ function invisibles() { if (document.getElementById('visibles').checked) { document.getElementById('hide1').style.visibility = 'hidden'; document.getElementById('hide2').style.visibility = 'hidden'; } else { document.getElementById('hide1').style.visibility = 'visible'; document.getElementById('hide2').style.visibility = 'visible'; } } function itemspp(sel) { var items=27; var itemsperpage = sel.options[sel.selectedIndex].value; //alert(itemsperpage); if (items%itemsperpage != 0) {document.getElementById('nop').innerHTML = (Math.floor(items/itemsperpage)+1);} else {document.getElementById('nop').innerHTML = (items/itemsperpage);} form.submit(); }/*-====================-*//*-- Action Functions --*//*-====================-*/ //when you add the php to this button id will be named with a php variable and the variable will be the item id function addToCart(input,form) { var m = 'item added to cart'; alertDisplay(m); } function search(input,form) { //alert('You Searched for: ' + document.getElementById('searchField').value); form.submit(); } /*==-Page Number Function-==*/ function pageNumber(input,form) { //alert('You selected ' + input.id); var maxPage = <?php echo $maxPage; ?>; var p = parseInt(document.getElementById('pageNumber').value); //input.id is numberField if ((input.id == 'pageField') && ( (isNaN(document.getElementById('pageField').value)) || (parseFloat(document.getElementById('pageField').value) % 1 !== 0) || (parseInt(document.getElementById('pageField').value) < 1) || (parseInt(document.getElementById('pageField').value) > <?php echo $maxPage; ?>) )) { alert('I\'m Sorry, ' + document.getElementById('pageField').value + '\ is not a valid page number. \nYou will be returned to page ' + document.getElementById('pageNumber').value); } else if (input.id == 'pageField') { document.getElementById('pageNumber').value = parseInt(document.getElementById('pageField').value); }//input.id is previousPage else if (input.id == 'previousPage' && p <= 1) { alert('You are already on page ' + p); } else if (input.id == 'previousPage') { p -= 1; document.getElementById('pageNumber').value = p; }//input.id is nextPage else if (input.id == 'nextPage' && p >= <?php echo $maxPage; ?>) { alert('You are on the last page.'); } else if (input.id == 'nextPage') { p += 1; document.getElementById('pageNumber').value = p; } else {alert('pageNumber Error');} form.submit(); } /*-===================================-*//*-- Button and Keystroke Submission --*//*-===================================-*/ function buttonSubmit(button,form) { if (button.id == 'searchButton') { search(button,form); } else if (button.id == 'previousPage' || button.id == 'nextPage') { pageNumber(button,form); } else if (button.id == 'addToCart') { addToCart(button,form); } else { alert('button click error'); alert(button.id); alert(form.name); } } function keystrokeSubmit(textbox,e,form) { e = e? e : window.event; var prskeyrtrn = e.keyCode? e.keyCode : e.which? e.which : e.charCode? e.charCode :null; if (prskeyrtrn == 13 && textbox.id == 'searchField') { search(textbox,form); } else if (prskeyrtrn == 13 && textbox.id == 'pageField') { pageNumber(textbox,form); } else{} } </script></head> <body onLoad="onLoad()"><!--=====================--><!--==begin top of page==--><!--=====================--><form name="headForm" id="headForm" method="POST" action="<?php echo $formpath; ?>"> <table width="100%" class="<?php echo $tablealignment; ?>" border="<?php echo $border; ?>"> <tr class="<?php echo $tealign; ?>"><!--left side of head --> <td width="<?php echo $edgewidth; ?>"> <table height="90" border="<?php echo $border; ?>" class="<?php echo $tablealignment; ?>" width="100%"> <tr class="<?php echo $tealign; ?>"><td><div name="pagediv" id="pagediv">Current Page: <?php echo $pageNumber; ?></div></td></tr> <tr class="<?php echo $tealign; ?>"><td><input type="text" id="pageField" name="pageField" placeholder="<?php echo $pageFieldDefaultValue; ?>" onkeypress="keystrokeSubmit(this,event,form)"></td></tr> <tr class="<?php echo $tealign; ?>"><td><input style="cursor:pointer" type="button" id="previousPage" name="previousPage" value="<?php echo $previousButton; ?>" onclick="buttonSubmit(this,form);"></td></tr> </table> </td><!--center of head --> <td class="<?php echo $tealign; ?>" width="80%"> <table height="90" border="<?php echo $border; ?>" class="<?php echo $tablealignment; ?>" width="100%"> <tr class="header"><td height="10%">Awesome Shape Store Catalog</td></tr> <tr class="<?php echo $tealign; ?>"><td height="90%"><div id="div_display" class="centop"></div></td></tr> </table> </td><!--right side of head --> <td width="<?php echo $edgewidth; ?>"> <table height="90" border="<?php echo $border; ?>" class="<?php echo $tablealignment; ?>" width="100%"> <tr class="<?php echo $tealign; ?>"><td><input type="text" id="searchField" name="searchField" placeholder="<?php echo $searchFieldDefaultValue; ?>" onkeypress="keystrokeSubmit(this,event,form)"></td></tr> <tr class="<?php echo $tealign; ?>"><td><input style="cursor:pointer" type="button" id="searchButton" name="searchButton" value="<?php echo $searchButton; ?>" onclick="buttonSubmit(this,form);"></td></tr> <tr class="<?php echo $tealign; ?>"><td><input style="cursor:pointer" type="button" id="nextPage" name="nextPage" value="<?php echo $nextButton; ?>" onclick="buttonSubmit(this,form);"></td></tr> </table> </td> </tr> </table><!--This is an invisible table and it holds the pageNumber--> <table class="tiny" border="<?php echo $border; ?>"> <tr> <td> Page Display Attributes: </td> <td colspan="2"> <input type="checkbox" checked name="visibles" id="visibles" value="show invisibles" onclick="invisibles();"> </td> </tr> <tr style="visibility:hidden" name="hideFields" id="hide1"> <td>Current page number</td> <td>Items per page:</td> <td>Number of pages:</td> </tr> <tr style="visibility:hidden" name="hideFields"id="hide2"> <td><input type="text" id="pageNumber" name="pageNumber" value="<?php echo $pageNumber; ?>"></td> <td> <select id="itemsperpage" name="itemsperpage" onchange="itemspp(this);"> <option value="1">1 item</option> <option value="3" selected="selected">3 items</option> <option value="6">6 items</option> <option value="9">9 items</option> <option value="18">18 items</option> <option value="27">all items</option> </select> </td> <td><div name="nop" id="nop">9</div></td> </tr> </table></form><!--===================--><!--==end top of page==--><!--===================--><!--===== This is a seperator ========== This is a seperator ========== This is a seperator =====--><!--===== This is a seperator ========== This is a seperator ========== This is a seperator =====--><!--===== This is a seperator ========== This is a seperator ========== This is a seperator =====--><!--==============================--><!--==begin main section of page==--><!--==============================--><div name="divbody' id="divbody"> <table> <tr> <td valign="top"><img src="images/catalogImages/circle_large_red.gif"></td> <td><table> <tr> <td valign="top"><b>Item ID:</b></td> <td>1</td> </tr> <tr> <td valign="top"><b>Name:</b></td> <td>Large Red Circel</td> </tr> <tr> <td valign="top"><b>Shape:</b></td> <td>Circle</td> </tr> <tr> <td valign="top"><b>Size:</b></td> <td>Large</td> </tr> <tr> <td valign="top"><b>Color:</b></td> <td><font color="red">red</font></td> </tr> <tr> <td valign="top"><b>Price:</b></td> <td>$3.00</td> </tr> <tr> <td valign="top"><b>Description:</b></td> <td>This is an amazing large <font color="red"><b>red</b></font> Circle with a super cool black boarder</td> </tr> </table></td> </tr> <!--add to cart button--> <form name="addToCart"> <tr><td><input type="button" value="Add to Cart" id= "addToCart" name="addToCart" onclick="buttonSubmit(this,form)"></td></tr> </form> </table></div><!--============================--><!--==end main section of page==--><!--============================--></body></html>
  9. Thanks. I got it figured out. The code ended up looking like this: <html><?php#error reportingerror_reporting(E_ALL);ini_set('display_errors','1');$link = mysqli_connect('127.0.0.1:3306', 'root', '4pp1353c', 'storedatabase');#check connectionif (mysqli_connect_errno()){printf("Connect failed: %s\n", mysqli_connect_error());exit();}#query string$query = "SELECT * FROM inventory ORDER by id ASC";$result = mysqli_query($link, $query);$row = mysqli_fetch_row($result);#variables$itemsperpage = $result->num_rows;$itemsperrow=3;$rowsperpage=$itemsperpage/$itemsperrow;?> <head> <title>nested loop</title> <style>/*sadly this is done without style*/ </style> <script type='text/javascript'>/*make some magic*/ </script></head> <body><?php echo $itemsperpage; ?> <table> <?php for ($r=0; $r<=$rowsperpage-1; $r++) { echo "<tr>"; for ($i=1; $i<=$itemsperrow; $i++) { $query = "SELECT * FROM inventory Where id =".($i+$r*3)." ORDER by id ASC"; $result = mysqli_query($link, $query); $row = mysqli_fetch_assoc($result); print ( "<td> <table> <tr> <!--catalog image--> <td valign='top'><img src='http://localhost/phpTestCode/web%20apps%20labs/Lab%2010/".$row["imageFilename"]."'></td> <td><table> <tr> <!--catalog id--> <td valign='top'><b>Item ID:</b></td> <td>".$row["id"]."</td> </tr> <tr> <!--catalog name--> <td valign='top'><b>Item Name:</b></td> <td>".$row["Product_name"]."</td> </tr> <tr> <!--catalog shape--> <td valign='top'><b>Shape:</b></td> <td>".$row["shape"]."</td> </tr> <tr> <!--catalog size--> <td valign='top'><b>Size:</b></td> <td>".$row["size"]."</td> </tr> <tr> <!--catalog color--> <td valign='top'><b>Color:</b></td> <td><font color=".$row['color'].">".$row["color"]."</td> </tr> <tr> <!--catalog price--> <td valign='top'><b>Price:</b></td> <td>$".$row["price"]."</td> </tr> <tr> <!--catalog description--> <td valign='top'><b>Description:</b></td> <td> This is an amazing".$row["size"]." <font color=".$row["color"]."><b>".$row["color"]."</b></font> ".$row["shape"]." with a super cool black border</td> </tr> </table></td> </tr> <!--add to cart button--> <!--id set by php--> <tr><td><input type='button' value='Add to Cart' id=".$row["id"]." onclick='buttonSubmit(this,form);'></td></tr> </table> </td>" ); } echo "</tr>"; } ?> </table> </body> </html>
  10. Hello and thanks in advance for any help you are able to supply. I think this issue stems from my lack of knowledge about arrays in php . I am able to get the info I need out of a database. I will supply that code below as well as my code that does not work. I am trying to populate a table with 3 elements in every row. every element is a nested table. Thanks again so much. I am using a nested loop to extract information from the database. This is an example of the errors I am getting. This code works: <?phperror_reporting(E_ALL);ini_set('display_errors','1');$link = mysqli_connect('127.0.0.1:3306', 'root', '4pp1353c', 'storedatabase');/* check connection */if (mysqli_connect_errno()){printf("Connect failed: %s\n", mysqli_connect_error());exit();}$query = "SELECT * FROM inventory ORDER by id ASC"; $result = mysqli_query($link, $query); //print_r($result); ?><html> <head> <title>test</title> <style>/*sadly this is done without style*/ </style> <script type='text/javascript'>/*make some magic*/ </script> </head> <body><!--begin catalog element--> <table> <?php /* fetch associative array */ while ($row = mysqli_fetch_assoc($result)) { print ( "<tr><!--catalog image--> <td valign='top'><img src='http://localhost/phpTestCode/web%20apps%20labs/Lab%2010/".$row["imageFilename"]."'></td> <td><table> <tr> <td valign='top'><b>Item ID:</b></td><!--catalog id--> <td>".$row["id"]."</td> </tr> <tr> <td valign='top'><b>Item Name:</b></td><!--catalog name--> <td>".$row["Product_name"]."</td> </tr> <tr> <td valign='top'><b>Shape:</b></td><!--catalog shape--> <td>".$row["shape"]."</td> </tr> <tr> <td valign='top'><b>Size:</b></td><!--catalog size--> <td>".$row["size"]."</td> </tr> <tr> <td valign='top'><b>Color:</b></td><!--catalog color--> <td><font color=".$row['color'].">".$row["color"]."</td> </tr> <tr> <td valign='top'><b>Price:</b></td><!--catalog price--> <td>$".$row["price"]."</td> </tr> <tr> <td valign='top'><b>Description:</b></td><!--catalog description--> <td> This is an amazing".$row["size"]." <font color=".$row["color"]."><b>".$row["color"]."</b></font> ".$row["shape"]." with a super cool black border</td> </tr> </table></td> </tr> <!--add to cart button--><!--id set by php--> <tr><td><input type='button' value='Add to Cart' id=".$row["id"]." onclick='buttonSubmit(this,form);'></td></tr> " ); }; ?> </table><!--end catalog element--> </body></html> <?php/* free result set */mysqli_free_result($result);/* close connection */mysqli_close($link);?> This code DOES NOT work. <html><?php#error reportingerror_reporting(E_ALL);ini_set('display_errors','1');$link = mysqli_connect('127.0.0.1:3306', 'root', '4pp1353c', 'storedatabase');#check connectionif (mysqli_connect_errno()){printf("Connect failed: %s\n", mysqli_connect_error());exit();}#query string$query = "SELECT * FROM inventory ORDER by id ASC";$result = mysqli_query($link, $query);$row = mysqli_fetch_assoc($result);#variables$itemsperpage=count($row,0);$itemsperrow=3;$rowsperpage=$itemsperpage/$itemsperrow;?> <head> <title>nested loop</title> <style>/*sadly this is done without style*/ </style> <script type='text/javascript'>/*make some magic*/ </script> </head> <body> <table> <?php for ($r=1; $r<=$rowsperpage; $r++) { echo "<tr>"; for ($i=1; $i<=$itemsperrow; $i++) { print ( "<tr> <!--catalog image--> <td valign='top'><img src='http://localhost/phpTestCode/web%20apps%20labs/Lab%2010/".$row[$i]["imageFilename"]."'></td> <td><table> <tr> <!--catalog id--> <td valign='top'><b>Item ID:</b></td> <td>".$row[$i]["id"]."</td> </tr> <tr> <!--catalog name--> <td valign='top'><b>Item Name:</b></td> <td>".$row[$i]["Product_name"]."</td> </tr> <tr> <!--catalog shape--> <td valign='top'><b>Shape:</b></td> <td>".$row[$i]["shape"]."</td> </tr> <tr> <!--catalog size--> <td valign='top'><b>Size:</b></td> <td>".$row[$i]["size"]."</td> </tr> <tr> <!--catalog color--> <td valign='top'><b>Color:</b></td> <td><font color=".$row[$i]['color'].">".$row[$i]["color"]."</td> </tr> <tr> <!--catalog price--> <td valign='top'><b>Price:</b></td> <td>$".$row[$i]["price"]."</td> </tr> <tr> <!--catalog description--> <td valign='top'><b>Description:</b></td> <td> This is an amazing".$row[$i]["size"]." <font color=".$row[$i]["color"]."><b>".$row[$i]["color"]."</b></font> ".$row[$i]["shape"]." with a super cool black border</td> </tr> </table></td> </tr> <!--add to cart button--> <!--id set by php--> <tr><td><input type='button' value='Add to Cart' id=".$row[$i]["id"]." onclick='buttonSubmit(this,form);'></td></tr> " ); } echo "</tr>"; } ?> </table> </body> </html>
  11. how so is the code interesting? and do you have any suggestions to make this code better? I'd love any feedback you have Here's what it ended up as: <html><?php$maxPage = 9;$pageNumber = $_POST['pageNumber'];if(!isset($pageNumber)){$pageNumber=1;}?> <head> <title>page number</title> <script type='text/javascript'> function page(input,form) { //alert(input.id); //alert(document.getElementById('pageNumber').value); var p = parseInt(document.getElementById('pageNumber').value); //input.id is numberField if ((input.id == 'pageField') && ( (isNaN(document.getElementById('pageField').value)) || (parseFloat(document.getElementById('pageField').value) % 1 !== 0) || (parseInt(document.getElementById('pageField').value) < 1) || (parseInt(document.getElementById('pageField').value) > <?php echo $maxPage; ?>) )) { alert('I\'m Sorry, ' + document.getElementById('pageField').value + '\ is not a valid page number. \nYou will be returned to page ' + document.getElementById('pageNumber').value); } else if (input.id == 'pageField') { document.getElementById('pageNumber').value = parseInt(document.getElementById('pageField').value); }//input.id is previousPage else if (input.id == 'previousPage' && p <= 1) { alert('You are already on page ' + p); } else if (input.id == 'previousPage') { p -= 1; document.getElementById('pageNumber').value = p; }//input.id is nextPage else if (input.id == 'nextPage' && p >= <?php echo $maxPage; ?>) { alert('You are on the last page.'); } else if (input.id == 'nextPage') { p += 1; document.getElementById('pageNumber').value = p; } else {alert('pageNumber Error');} form.submit(); } function keystrokeSubmit(textbox,e,form) { e = e? e : window.event; var prskeyrtrn = e.keyCode? e.keyCode : e.which? e.which : e.charCode? e.charCode :null; if (prskeyrtrn == 13 && textbox.id == 'pageField') { //alert(textbox.id); page(textbox,form); } } function buttonSubmit(button,form) { if (button.id == 'previousPage' || button.id == 'nextPage') { //alert(button.id); page(button,form); } } </script></head> <body> <form method="POST" action="<?php echo ($_SERVER['PHP_SELF']); ?>"> <input type="text" name="pageField" id="pageField" placeholder="Jump to Page" onkeypress="keystrokeSubmit(this,event,form);"><br> <input type="text" name="pageNumber" id="pageNumber" value="<?php echo $pageNumber; ?>"><br> <input type="button" name="previousPage" id="previousPage" value="previous page" onclick="buttonSubmit(this,form);"> <input type="button" name="nextPage" id="nextPage" value="next page" onclick="buttonSubmit(this,form);"> </form> <?php print("The current page number is ". $pageNumber); print("<br>");?> </body> </html>
  12. Hello, I'm trying to save some keystrokes and I have assigned document.getElementById('pageNumber').value; to a variable. The first section of code is the function that I am having trouble with. The second section is all the code I am currently using. In the if statement the last alert will give the correct value but the if statement won't populate on the web page. If I copy the document.getElementById('pageNumber').value statement and replace it for the variable p in the if statement p=1, then the value is reassigned and populated properly on the page. Any ideas? Thanks function page(input, form) { alert(input.name); alert(form.pageNumber.value); var p = document.getElementById('pageNumber').value; if(p < 1) { p = 1; } alert(p); } <html><head> <title>test</title> <script type='text/javascript'>/*make some magic*/ function page(input, form) { alert(input.name); alert(form.pageNumber.value); var p = document.getElementById('pageNumber').value; if(p < 1) { p = 1; } alert(p); } function keystrokeSubmit(textbox,e,form) { e = e? e : window.event; var prskeyrtrn = e.keyCode? e.keyCode : e.which? e.which : e.charCode? e.charCode :null; if (prskeyrtrn == 13 && textbox.id == 'pageField') { //alert(textbox.id); page(textbox,form); } } function buttonSubmit(button,form) { if (button.id == 'previousPage' || button.id == 'nextPage') { //alert(button.id); page(button,form); } } </script></head> <body> <form name="headForm" id="headForm" method="POST" action="<?php echo ($_SERVER['PHP_SELF']); ?>"> <input type="text" name="pageField" id="pageField" placeholder="enter a page number" onkeypress="keystrokeSubmit(this,event,form)"> <br> <input type="text" style="visibility:visible" name="pageNumber" id="pageNumber" value="0"> <br> <input type="button" name="nextPage" id="nextPage" value="nextPage" onclick="buttonSubmit(this,form);"> <input type="button" name="previousPage" id="previousPage" value="previousPage" onclick="buttonSubmit(this,form);"> </form> </body> </html>
  13. Ingolme, I had to go with this ultimately to get it to work. I'm not sure on the specifics of all the pieces but I know this works. Thanks again for all your help! var timer = setTimer("",0); /* reset the timer for add to cart display or other messages */function alertDisplay(d){ var time=5000; document.getElementById("div_display").innerHTML=d; clearTimeout(timer); timer=setTimeout("document.getElementById('div_display').innerHTML=''", time);}
  14. if I save the code as .html it works fine. I am now saving it as.php and it hasn't worked right since. the expected behavior isclick button 1-message 1 display for 2 seconds click button one-message 1 is displayclick button 2 before 2 seconds elapses-message 2 is displayed for 2 seconds or until another button is pushed whichever comes first the problem is i can click 20 buttons but the timer never resets.
×
×
  • Create New...