-
Posts
3,372 -
Joined
-
Last visited
-
Days Won
18
Everything posted by Muddy_Funster
-
Assuming that your table has a numerical index key then you can use SELECT COUNT(id) FROM tableName assigne that to a variable and have a $counter on the page that cross refferences a SELECT image, price FROM tableName where id = $counter . This is not tested and is very messy as I just knocked it up quick, but I would suggest something a little like: <?php $qry = "SELECT COUNT(id) FROM tableName"; $count = mysql_fetch_array(mysql_query($qry)); $db_count = $count['0']; $_SESSION['max_count'] = $db_count; $_SESSION['min_count'] = $db_count - $db_count; if ($_SESSION['browsing'] != "Yes"){ $counter = $min_count; $_SESSION['browsing'] = "Yes"; } else{ $counter = $_POST['new_counter'] } if ($counter => $_SESSION['min_count'] && $counter =< $_SESSION['max_count']){ echo 'Image No. '.$counter.' of '.$_SESSION['max_count']; $get_image = "SELECT image, price FROM tableName WHERE id = ".$counter; $got_image = mysql_query($get_image); $image_info = mysql_fetch_assoc($got_image); printf $image_info['image']; echo "<br> Priced at &dolar;".$image_info['price']; if ($counter > $_SESSION['min_count']){ echo '<form action ="PHP_SELF" method="post" type="submit"><input type="hidden" value="'.($counter - 1).'" name="new_counter" /></form>'; } elseif ($counter < $_SESSION['max_count']){ echo '<form action ="PHP_SELF" method="post" type="submit"><input type="hidden" value="'.($counter + 1).'" name="new_counter" /></form>'; } } else {echo 'Value out of range, an error has occured';} ?> **I STRESS this is just to give you the idea of what I am talking about - this has not been error checked at all!!** Hope it helps though
-
PHP script to query Mysql database from url
Muddy_Funster replied to jamjam's topic in PHP Coding Help
Effectivly the include ""; statement will be your bigest friend. You will have a top page that will query your database for formating information. this will simply be raw html stored in a text field in your database. You will then echo this out. when you echo raw html it's just the same as if you coded the page directly. Within the formating you can then use the include "content1.php"; to auto load the content of each formated area. This will be a php page that runs another query on your database and echos out the contents for that format section be it a table, heading, frame or even an image. All the information that you would normaly type into the flat html pages can be entered into the database and called back using a query in any php page at any point when building the end page. Structure your database and index.php correctly and you will even be able to seamlesly add new pages with only having to enter the content that it will display. Something you may want to note though - you will still need to use forms for your input if you are planning on entering data through php instead of directly into the database. -
PHP script to query Mysql database from url
Muddy_Funster replied to jamjam's topic in PHP Coding Help
It's very possible. And, given a few days and a couple hundred green backs I'd post you your code up Seriously though - if you are going to administer the site you really need to get your hands dirty and build it yourself. It is the best way to get to know what's going on and learn what you will need to fix anything that breaks or change/expand the site when need or desire come along. By all meens we will help when you get stuck, or want to try something tricky and want advice, but you sould have a go at the ground work on your own. There are lots of resources out there that can teach you php and SQL some in conjunction with each other and some not. If there is some specific aspect of the progect that you are looking for help with ask away. -
Basic javascript can also run off an onClick or onChange function of a form item, and I think *not certain here so someone will need to yay or nay this* that you can nest a php include within a java function. Try a search on "Java onChange" and see what you get.
-
hmmm....me thinks you need a better book Looking at it though, your errors that you mentioned are coming from 1. addressing an array variable without first telling it to look in the array if ($Voornaam ... rather than if($inputform['Voornaam'] ... and 2. checking against an array that has not been created $formerrors['Voornaam'] fire up your form field names and your table field names and we will see what we can come up with
-
You're welcome. And I did say that the "id" field was an assumption Good luck
-
Try: $sql = 'INSERT INTO results(rollno,name,maths,physics,chemistry,enlish,hindi) VALUES('.$_POST['rollno'].', \''.$_POST['uname'].'\', '.$_POST['maths'].', '.$_POST['physics'].', '.$_POST['chemistry'].', '.$_POST['english'].', '.$_POST['hindi'].')'; this is assuming that name is the only string field in your database.
-
Prevent a form from processing if required fields aren't completed?
Muddy_Funster replied to JoeAM's topic in PHP Coding Help
ok, here's the quick and dirty play on it missing out the if(isset($_POST['fieldValue']){} and keeping it to direct variable checking: <?php //set variables from form $height = $_POST["height"]; $width = $_POST ["width"]; $length = $_POST["length"]; $name = $_POST["client_name"]; $number = $_POST["client_phone"]; $email = $_POST["client_email"]; if ($name == ''){ echo "You MUST fill in the Name field!"; include "yourFormPage.html"; } elseif ($number == ''){ echo "You MUST fill in the Number field!"; include "yourFormPage.html"; } elseif ($email == ''){ echo "You MUST fill in the E-Mail field!"; include "yourFormPage.html"; } else { rest of page code } you can expand on each of the if statements to include more failure criteria (such as no @ symbol in the email field or letters in the number one) but you're better to read up on those carefully to get the best out of implementing them. This should do what you need just now. -
Hows about "SELECT * FROM $stand WHERE id NOT IN (SELECT seatid FROM booking WHERE eventid = $event AND stand = '$stand') GROUP BY id " (assuming id is the field that you are returning). Also, as a rule of thumb, avoid SELECT * wherever possible.
-
you need to quote your $_POST returns eg $_POST['maths']
-
Retrieving data from mysql table and inserting it in a news feed.
Muddy_Funster replied to Fenhopi's topic in PHP Coding Help
What database are you using? What's your table and fields named as? When you say that each record should go to it's own table, are you reffering to an html table on the page are are you making a table in the database for each post once it has been created (unlikely I know but better to clear it up just now)? If it's just for an html table is there a reason why you need a new table for each? Sorry to answer a question with a bunch of other ones, but if you let us know this we can help much more efectivly. -
If you could post what it is you are trying to do it would help. You can perform conditional checking on query results, but you can't actualy query a result set once you have retrieved it out of the database.
-
Prevent a form from processing if required fields aren't completed?
Muddy_Funster replied to JoeAM's topic in PHP Coding Help
Not exactly, but you can have checks in the php that will bounce back a message and the original form page if certain fileds are left blank. You can also use session variables or a hidden form on your php page to refill the information that was originaly entered on the form when it reloads. Check out the php manual for "isset()" for the best way to check empty variables. -
Unquote the input variable. You have it showing as '17' which tells MySQL that it's a sting. when you try to compare a sring to a numeric field value it get's upset. You should only quote string field variables (varchar, text, enum etc) and never quote numeric (int, float, decimal etc).
-
OK, the error on line 89 is because you missed out the $ on query. The other SQL error I suspect is because there is no space between the = and the 17 after the WHERE clause.
-
Hi, at first glance I can see that Herhold and Sommer Rock aren't quoted so will throw up problems. It may also be that the double spacing is upsetting the query. Try and fix the formating so that the double spacing is cleared up. somthing like this should work: $query = 'UPDATE ticket_user SET order_nr = \''.$_POST['order_nr'].'\', navn= \''.$_POST['navn'].'\', billet_type = \''.$_POST['billet_type'].'\', antal = '.$_POST['antal'].', afsendt = '.$_POST['afsendt'].', billet_nr ='.$_POST['billet_nr'].', WHERE order_id ='.$_POST['order_id']; Could you give an example data set for each of the variables if changing that doesn't fix it? also, could I recomend breaking out single quotes for the stings rather than double quoting them? eg. $query = 'UDATE table_name SET varchar_field = \''.$variable.'\', rest of statement'; It souldn't make much of a difference, but MySQL "preffers" single quotes as string containers.