Jump to content

GingerRobot

Staff Alumni
  • Posts

    4,082
  • Joined

  • Last visited

Everything posted by GingerRobot

  1. As far as i am aware, this is a job for mod_rewrite.
  2. Do you not just select and display results where the club field equals club 2?
  3. Did you forget these two lines: [code] $name=explode("<br>", $row['resourcesneeded']); $amountIn = count($name); [/code] If you dont include those, you'll get the output of two empty arrays.
  4. Also, you can access each one invididually using my version. There is an array containing each of the information. For instance, $items[0] contains Nails, $numbers[0] contains 200 etc
  5. My version. I think the others are going to run into troubles with the fibre glass because it has a space in the name This code: [code] <?php $row['resourcesneeded'] = "200 Nails<br>710 Brick<br>340 Wood<br>200 Insulation<br>20 Carpet<br>5 Fibre Glass"; $name=explode("<br>", $row['resourcesneeded']); $amountIn = count($name); $numbers = array(); $items = array(); for($x = 0; $x < $amountIn; $x++){ $strpos = strpos($name[$x]," "); $number = substr($name[$x],'0',$strpos); $item = substr($name[$x],$strpos); $numbers[] = $number; $items[] = $item; } print_r($numbers); echo '<br />'; print_r($items); ?> [/code] Produces: Array ( [0] => 200 [1] => 710 [2] => 340 [3] => 200 [4] => 20 [5] => 5 ) Array ( [0] => Nails [1] => Brick [2] => Wood [3] => Insulation [4] => Carpet [5] => Fibre Glass )
  6. Ok, to start with you need to make this parts here: echo($row["company_name"]); A link. If you have a unique ID, then pass that in the query string, if not, then use the company: [code] <?php echo "<a href='viewcompany.php?id=".$row["id"]."'>".$row["company_name"]."</a>"); ?> [/code] Then, on your new page, which ive called viewcompany.php: [code] <?php $id = mysql_real_escape_string($_GET['id']); $sql = "SELECT * FROM `company` WHERE `id`='$id'"; $result = mysql_query($sql) or die(mysql_error()); ?> [/code] Ive not added anything about outputting the code because ive no idea how you were planning on layout it out or what information you have. But thats the gerneral idea. Also, if you do need to change it to using the company name rather than an ID, then you'll have to modify it accordingly.
  7. Are you sure you're using the script i gave you? Those quotes weren't present in that version. Also, those statements there have nothing to do with those statements, and they dont really have a lot to do with a query either. What makes you think that it is those that are causing the problem?
  8. Well i dont quite understand, because it appears that there IS php support... As shown by the working link which contains phpinfo();
  9. Do you mean that you want to be able to sort one of 4 columns? In which case, just modify it a little. Make the links like: <a href='yourpage.php?sort=asc&field=field1'>Sort By Field 1 Asc</a> then the code: [code] <?php if(isset($_GET['sort'] && isset($_GET['field']){ $sort = mysql_real_escape_string($_GET['sort']); $field = mysql_real_escape_string($_GET['field']); $sql = "SELECT * FROM `yourtable` WHERE.... ORDER BY `$field` '$sort'"); mysql_query($sql) or die(mysql_error()); }else{ //perfrom the query without sorting } //show the data ?> [/code] I dont think you're gonna get shorter for sorting data. And its not that long anyway is it?
  10. Hmm, well i cant see anything really wrong there, perhaps its got a bit confused with the numbers not in quotes and a few missing spaces. Try: [code] <?php // build and execute the query //Age Query $query= "SELECT * FROM `boxers` WHERE `age` >="; $low = $age -1; $high = $age +1; $query .= "'$low'"; $query .= " AND `age` <="; $query .= "'$high'"; //Weight Query $low=$weight-3; $high=$weight+3; $query .= " AND `weight` >="; $query .= "'$low'"; $query .= " AND `weight` <="; $query .= "'$high'"; //Bout Query $low= $bouts-3; $high= $bouts+3; $query .= " AND `bouts` >="; $query .= "'$low'"; $query .= " AND `bouts` <="; $query .= "'$high'"; $results = mysql_query($query) or die(mysql_error().'<br />QUERY:'.$query); //loop through results while ($row = mysql_fetch_array($results)) {   // print out the code for each row   echo '   <tr>       <td>'.$row['first_name'].'</td>       <td>'.$row['last_name'].'</td>       <td>'.$row['age'].'</td>       <td>'.$row['weight'].'</td>       <td>'.$row['bouts'].'</td>       <td>'.$row['senior'].'</td>       <td>'.$row['gender'].'</td>   </tr> '; } ?> <!-- Close Table --> </table> </body> </html> [/code] If that doesn't work, see if you can remove bits of the query until it works to narrow down the problem
  11. Something like this should work: [code] <?php $sql = "SELECT * FROM `cart` WHERE `session_id`='$sessionid'"; $result = mysql_query($sql) or die(mysql_error()); $total_weight = 0; while($row=mysql_fetch_assoc($result)){ $product_id = $row['product_id']; $qty = $row['qty']; $sql = "SELECT `weight` FROM `products` WHERE `product_id`='$product_id'"; $weight_result = mysql_query($sql) or die(mysql_error()); $weight = mysql_result($weight_result,0,"weight"); $item_weight = $weight * $qty; $total_weight = $total_weight+$item_weight; } echo "Total weight: $total_weight"; ?> [/code] Obviously you're gonna have to modify it a bit to work with your database and variables. Its also untested.
  12. Im guessing that php insn't installed on that site. If you view the source you see your script, which isn't what should be happening. Try a file with just [code] <?php phpinfo(); ?> [/code] in it
  13. [code] <?php $sql = "DELETE FROM `yourtable` WHERE `key`='000001' AND `file`='af.txt'"; mysql_query($sql)or die(mysql_error()); ?> [/code] Im assuming thats what you were after.
  14. Yes, it does't like the endif. In fact, ive never seen that syntax before, although it looks like you use it with colons instead of braces. Anyway, if i remove the end if and run the script, i get redirected to yahoo.com
  15. Ok, i see. I give this a go: [code] <?pjp require("connect.php"); $id = $_GET['id']; //im assuming that currently it works because register_globals is turned on, but really you should do this $query = " SELECT * FROM news WHERE id='$id'"; $result = mysql_query($query)or die(mysql_error().'<br />QUERY:'.$query);; mysql_close(); //you shouldn't really need the while statment here, there should only be one news article for each ID. $news = mysql_result($result, 0, "news"); $title = mysql_result($result, 0, "title"); ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <p>   <input type="hidden" name="ud_id" value="<? echo $id; ?>"> <p>News Title:   <input name="ud_title" type="text" id="ud_title" value="<? echo $title; ?>"> </p> <p>News:<br>   <br>   <textarea name="ud_news" cols="75%" rows="15" id="ud_news"><? echo $news; ?></textarea> </p> <p>   <input name="Update" type="Submit" id="Update" value="Update"> </p> </form> <p> </p> <form name="form1" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>"> News ID Number: <input name="id" type="text" id="id" size="3" maxlength="3"> <input name="Get" type="submit" id="Get" value="Get"> </form> <p>&nbsp; </p> <?php if ($_POST['Update']) { require("connect.php"); $id=$_POST['ud_id'];//change to the ID comming from the POST form. I think this was probably the route of your problems $ud_title = $_POST['ud_title']; $ud_news = $_POST['ud_news']; $query = "UPDATE news SET title='$ud_title', news='$ud_news' WHERE `id`='$id'"; mysql_query($query) or die(mysql_error().'<br />QUERY:'.$query); echo "The News Article: <b>$ud_title</b> ID: <b>$id</b> has been updated"; mysql_close(); } ?> [/code] Ive put a few comments in there to explain a bit of what ive done. The only other thing is that ive removed the field where you would edit the ID. You're going to need this to be unique and remain constant for this kind of thing.
  16. Ive made a few changes to your code. Firstly, i think there were a few problems with the query itself. I think the idea was that you had one query, but you had actually started 3 differant ones. So ive modified it into a single query. Second, i was getting some syntax errors with the heredoc system (the <<<END part) and im not overly familiar with it, so to save time, ive changed that. Give this a go. [code] <?php $age=$_POST['age']; $weight=$_POST['weight']; $bouts=$_POST['bouts']; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> </head> <body> <?php $link = mysql_connect('mysql2.streamline.net', 'smallheath', '-') or die('Could not connect: ' . mysql_error()); $db_selected = mysql_select_db('smallheath', $link) or die ('Error while connecting to database: ' . mysql_error()); ?> <!--set up the table --> <table border="1" cellpadding="5">   <tr>       <th>First Name</th>       <th>Last Name</th>       <th>Age</th>       <th>Weight</th>       <th>Bouts</th>       <th>Senior</th>       <th>Gender</th>   </tr> <?php // build and execute the query //Age Query $query= "SELECT * FROM boxers WHERE age >="; $low = $age -1; $high = $age +1; $query .= $low; $query .= " AND `age` <="; $query .= $high; //Weight Query $low=$weight-3; $high=$weight+3; $query .= " AND `weight` >="; $query .= $low; $query .= " AND `weight` <="; $query .= $high; //Bout Query $low= $bouts-3; $high= $bouts+3; $query .= "AND `bouts` >="; $query .= $low; $query .= "AND `bouts` <="; $query .= $high; $results = mysql_query($query) or die(mysql_error().'<br />QUERY:'.$query); //loop through results while ($row = mysql_fetch_array($results)) {   // print out the code for each row   echo '   <tr>       <td>'.$row['first_name'].'</td>       <td>'.$row['last_name'].'</td>       <td>'.$row['age'].'</td>       <td>'.$row['weight'].'</td>       <td>'.$row['bouts'].'</td>       <td>'.$row['senior'].'</td>       <td>'.$row['gender'].'</td>   </tr> '; } ?> <!-- Close Table --> </table> </body> </html> [/code]
  17. Im a little confused as to why there are two forms on this page. Is the second one used to select the news article that you want to edit, and the first used to actually edit the article?
  18. Firstly, you'll need a link like: <a href='yourpage.php?sort=asc'>Sort Asc</a> and similiarly, <a href='yourpage.php?sort=desc'>Sort Desc</a> Then, on your page, use GET to retrieve the sort method: [code] <?php if(isset($_GET['sort']){ $sort = mysql_real_escape_string($_GET['sort']); $sql = "SELECT * FROM `yourtable` WHERE.... ORDER BY `yourfieldname` '$sort'"); mysql_query($sql) or die(mysql_error()); }else{ //perfrom the query without sorting } //show the data ?> [/code] Obviously its just a sample, but without any of your code i cant really help you further.
  19. Welcome to the board :) Ok, a couple of things, firstly, what does happen when you run the script? Second, when dealing with mysql problems, add an or die statement to the query. For instance your query here: [code] <?php $query = "UPDATE news SET id='$id', title='$ud_title', news='$ud_news'"; mysql_query($query); ?> [/code] Can be changed to [code] <?php $query = "UPDATE news SET id='$id', title='$ud_title', news='$ud_news'"; mysql_query($query) or die(mysql_error().'<br />Query:'.$query); ?> [/code] This will show any errors, and if they are, give the mysql error along with what was actually passed into the query. Finally, do you think you could edit your post so your code uses full php tags (<?php) rather than the short tags (<?) - otherwise you dont get the syntax highlighting and it makes it a bit hard to read.
  20. I think we're really going to need some information on your database structure to help you
  21. Try this: [code] <?php $str = "example2, 3:35&example1, 0:10"; $lines = explode("&",$str); $array1 = array(); $array2 = array(); foreach($lines as $lines){ $parts = explode(",",$lines); $array1[] = $parts[0]; $array2[] = trim($parts[1]); } print_r($array1); print_r($array2); ?> [/code] Outputs this: Array ( [0] => example2 [1] => example1 ) Array ( [0] => 3:35 [1] => 0:10 )
  22. Well thats not what thorpe suggested. What is the output if you add in the debugging that he proposed?
  23. Well if you only have the two bits of info that you are using here(titles and subjects) then id use the keys and values of a single array to store the information. i used a textfile just to test this with c;seDp#b a;seDp#a b;seDp#c contained within it. Here is the code i used. [code] <?php $contents = file_get_contents('info.txt'); $lines = explode("\n",$contents); $titles_subjects = array(); foreach($lines as $lines){ $split = explode(";seDp#",$lines); $titles_subjects[$split[0]] = $split[1]; } //the key stores the titles, and the value stores the subjects ksort($titles_subjects);//sort by key for title sorting reset($titles_subjects); echo 'Sorted by titles:<br/><table><th>Title</th><th>Subject</th>'; foreach($titles_subjects as $output){ echo '<tr><td>'.key($titles_subjects).'</td><td>'.$output.'</td></tr>'; next($titles_subjects); } echo '</table><br /><br />'; //with thanks to crudo at pinknet dot cz (PHP site for the sort function) for this method of sorting an array without loosing the keys - switches keys and values, sorts by key, then switches back. Normal sort function replcaes keys with numerical values. $temp=array_flip($titles_subjects); ksort($temp); $titles_subjects=array_flip($temp); reset($titles_subjects); echo 'Sorted by subjects:<br/><table><th>Title</th><th>Subject</th>'; foreach($titles_subjects as $output){ echo '<tr><td>'.key($titles_subjects).'</td><td>'.$output.'</td></tr>'; next($titles_subjects); } echo '</table>'; ?> [/code]
×
×
  • 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.