Jump to content

davidf85

Members
  • Posts

    21
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

davidf85's Achievements

Member

Member (2/5)

0

Reputation

  1. I am building a shopping cart with PHP and working with a tutorial (http://jameshamilton.eu/content/simple-php-shopping-cart-tutorial) I am putting together the cart and there is some coding $sql = sprintf("SELECT name, description, price FROM php_shop_products WHERE id = %d;", $product_id); That i do not understand. Here it is "WHERE id = %d;" I have never seen this before and am wondering what it means or how to work with this syntax
  2. I am getting this error: Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/content/20/8917120/html/goldenfruit/test.php on line 11 for this code: <?php $connect = mysql_connect('DB credentials removed'); if (!$connect) { die('Could not connect: ' .mysql_error()); } $data = mysql_query("SELECT * FROM fruits"); $row = mysql_fetch_row($data); echo $row[0]; echo hello; ?> I cannot seem to find the error in this. Can anyone help?
  3. How does PHP continuity exist in different php tags? for example, if i connect to a database in a header, and close the tag, can I still work off of the same database in another tag?
  4. Can I use <? ?> to enclose code?
  5. I was not surrounding the code with tags I as thinking I could freely write HTML within PHP tags.
  6. <?php session_start(); ?> <body> <div> etc etc php will not work within these lines. </div> </body>
  7. Yes. Placing php code at the top works fine. But within the HTML the page becomes void.
  8. I am writing a shopping cart, and so far I have made the page in html, only a very simple front end with a logo a couple of links and a template for the items. I am trying to add the <?php and ?> tags to the page but when I try and view the page in IE it comes blank. If I add <?php echo HELLO; ?> to the top of the page, above all the HTML it works. but not when I enclose the entire page... even though there is no php coding on the page.
  9. <tr> <td align=center> <b>Classified Market</b> <br> United States<br> New Jersey<br> Atlantic County<br> <i>Animals</i><br><br><br> </td> </tr> <tr> <td> <table> <?php $link = mysql_connect('localhost','root', 'root') or DIE(mysql_error()); $db = mysql_select_db('advertisements') or DIE(mysql_error()); $page_name = "http://localhost/pagination.php"; $count = mysql_query("SELECT count(*) as cnt FROM advertisements"); if(!$count){ die("Error querying the Database:".mysql_error()); } $a=mysql_fetch_object($count); $total_ads = $a->cnt; $page = (isset($_GET["page"]))?$_GET["page"] : 1; $limit = (isset($_GET["limit"]))?$_GET["limit"] : 10; if((!$page) || (is_numeric($page) == false) || ($page < 0) || ($page > $total_ads)) { $page = 1; } if((!$limit) || (is_numeric($limit) == false) || ($limit < 10) || ($limit > 50)) { $limit = 10; } $total_pages=ceil($total_ads/$limit); $set_limit=($page*$limit)-$limit; $data=mysql_query("SELECt * FROM advertisements LIMIT $set_limit, $limit"); if(!$data) die(mysql_error()); $no_row = mysql_num_rows($data); if($no_row == 0) die("There are no advertisements in this category."); echo("<br>Records Per Page: <a href=$page_name?limit=10page=1> 10</a> | <a href=$page_name?limit=25&page=1> 25</a> | <a href=$page_name?limit=50&page=1> 50</a><br>"); $prev_page = $page - 1; if($prev_page >= 1) { echo("<b><<</b> <a href=$page_name?limit=$limit&page=$prev_page> <b>Previous Page</b></a>"); } for($a=1;$a<=$total_pages;$a++) { if($a == $page) { echo("<b>$a</b>"); } else { echo(" <a href=$page_name?limit=$limit&page=$a>$a </a>"); } } $next_page = $page + 1; if($next_page <= $total_pages) { echo(" <a href=$page_name?limit=$limit&page=$next_page><b>Next Page</b></a>>>"); } ?> </table> MOD EDIT: code tags added.
  10. I am working on a page that has about 20 lines of php that I am placing below a table row. I have HTML content in the Table, and PHP code echoes another table row, but between the previous HTML row and the php echoed row, is a lot of white space. I am wondering if there is a way to keep the rows tight.
  11. $page = (isset($_GET["page"]))?$_GET["page"] : 1 ; This is from a pagination script, and I am wondering what the ? means here, and what the : does.
  12. Can there be php tags (<?php ?>) before and after abody of HTML with out any scripting?
  13. I am trying to understand PHP While Loops. For example. $info=mysql_fetch_array($query); will create an array of a mysql query. how does while($info=mysql_fetch_array($query) { echo $info['1']; } ensure that each element of the array is echoed. It seems that $info is a one time statement that grabs an array, how does adding While make it capable of being extended into rows? To me this says While this is true, do this. But if it is true once, how does PHP know when to stop?
  14. I am trying to create a link with an ID from one of my MySQL records. $data = mysql_query("SELECT * FROM USERS"); $info = mysql_fetch_array($data); echo "<a href=a.php?'$info['id']'>hello</a>"; is what I am attempting, but this does not work. Any ideas?
  15. I am have some trouble grasping the basics of PHP. One thing in particular is how the session_start() function, can operate throughout every php page, but variables (at least I believe this to be so) are particular to each script. For example... example.php <?php session_start() ?> <?php $a="b"; ?> <?php $a='c'; ?> Does this just mean the SESSION function is an overlaying feature of PHP, that operates throughout the page regardless of what scripts are made and what variables are set? Would <?php $a="b"; $_SESSION['a']=$a ?> <?php $a='c'; $_SESSION['a']=$a ?> ultimately result as $_SESSION['a']= c ???
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.