Jump to content

hitman6003

Members
  • Posts

    1,807
  • Joined

  • Last visited

Everything posted by hitman6003

  1. [quote]1) Is my logic with this correct?[/quote] Yes. [quote]2) How hard is it to create a class I can use and learn from that will do the above[/quote] Not very. [quote]3) How's the weather where you are?[/quote] Hot, and humid. I sometimes use a mysql abstraction class from this website:  http://jaws.townsville.nl/, called ActiveRecord.  Most of the time I will write my own, however, this one is pretty good in my opinion.  If nothing else, you can use it as an example to learn something for your class. phpclasses.org also has about a million mysql classes that you can take a look at.
  2. [quote] 1) Lets say a person was searching for "John Smith" they could enter "John Smith" or "John" or "Smith" and it would work.  I would like to improve my search so that if a person searched for "John Smith" it would also find results for "John T. Smth" or " John Q. Smith" etc.  Is there an easy way to do this? [/quote] I would say to break the string apart and then do a search for both words and only return the results that have both in them, regarless of order or what's between them. [quote]2)  How can I sort the $year field?[/quote] You have to create a multidimensional array, then sort it.  You can create a normal array, then use array_multisort, or you can create an array that has the year as the keys, and then sort the keys.  Just be careful with the latter because duplicate keys will over write eachother. [quote]3)  For each record, the data in my $info is 2 or 3 sentences long.  When the current script returns a result, there is only 1 space between sentences even though there are 2 in my database.  Any suggestions on how I can fix this?[/quote] What do you mean it only returns one space but there are two in the db?  Please clarify.
  3. Write your query like any other join query: [code]SELECT table1.field1, table1.field2, table2.field1 FROM table1   LEFT JOIN table2 ON table1.field = table2.field WHERE table1.somefield = 'somevalue';[/code] THen loop through the results like normal and create a table.
  4. Your code is very messy. [code]<? include 'db.php'; $child_id = $_REQUEST['id']; $result = mysql_query("SELECT childfirstname, childlastname, childdob, child_id FROM children WHERE children.child_id = '$child_id'") or die(mysql_error()); list($first, $last, $dob, $child_id) = mysql_fetch_assoc($result); ?> <form id="updateinfo" name="updateinfo" method="post" action= "<? echo "CodeUpdatechild.php?id=$child_id";?>"> <table> <tr> <td>&nbsp;</td> <td>Child's First Name:</td> <td><input id="childfirstname" name="childfirstname" type="text" value="<?php echo $first; ?>"></td> </tr> <tr> <td>&nbsp;</td> <td>Child's Last Name:</td> <td><input id="childlastname" name="childlastname" type="text" value="<?php echo $last; ?>"></td> </tr> <tr> <td>&nbsp;</td> <td>Child's DOB:</td> <td><input id="childdob" name="childdob" type="text" value="<?php echo $dob; ?>"></td> </tr> <tr> <td>&nbsp;</td> <td>Sex:</td> <td> <select name="childsex" id="childsex"> <option></option> <option>Male</option> <option selected>Female</option> </select> </td> </tr> <tr> <td colspan="3"><input type="submit" name="Submit" value= Update></td> </tr> </table> </form> <? session_start();  // Start Session?> <title>code update</title> <? include 'db.php'; $child_id = $_REQUEST['id']; $firstname= $_POST['childfirstname']; $lastname = $_POST['childlastname']; $dob = $_POST['childdob']; $sex = $_POST['childsex']; // check to  make sure update does not create douplicate value $sql_child_check = mysql_query("SELECT * FROM children WHERE childlastname = '$lastname' AND childfirstname = '$firstname' AND childdob = '$dob'")or die(mysql_error()); $child_check = mysql_num_rows($sql_child_check); $row = mysql_fetch_assoc($sql_child_check); $child_id = $row['child_id']; if(($child_check == 1)){ $msg .= '<div style="width:325px" id= "formmessage">'; $msg .= "The change you made resulted in finding <b>".$firstname. ' '. $lastname. "</b> in the database<br> <br>  <a href='deleteParent.php?id=$child_id&user_id=$user_id'>Delete</a> current person and use <a href='addchild.php'>Add Parent</a> to locate person and create link:<br />"; $msg .= '</div>'; include 'getchildren.php'; exit (); } if(($child_check == 0)){ mysql_query("UPDATE children SET childfirstname = '$firstname', childlastname = '$lastname', childdob = '$dob' WHERE child_id = '$child_id'")or die(mysql_error()); $msg .='<div style="width:325px" id= "formmessage">';  $msg .= $firstname. ' '. $lastname. " has been updated."; $msg .= '</div>'; include 'getchildren.php'; } ?>[/code] Echo out your query, then execute it in phpMyAdmin or MySQL query browser and make sure that it is executing correctly.
  5. You form method is post, but you are using the get array: [code]} elseif ($mode == "change") {     $body = $_GET['body'];     if ($body == "") {     print "<table border='1' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#000000' width='100%'>   <tr>....[/code] Change that to [code]$body = $_POST['body'];[/code]
  6. Use the javascript function split to seperate your day display into seperate items... [code]var text = selectedoption.split(" "); var day = text[0];[/code] Something similar to that should work. JS is not that different from PHP, the functions are just a little different, so you can do nearly all the same string manipulations.
  7. I use magpie to do most of my rss feed reading: http://magpierss.sourceforge.net/
  8. [code]<?php $file = "./logs.txt"; $limit = "5"; $log = file($file); $lines = count($log); if ($lines > $limit + 19){ if (!$handle = fopen($file, 'w')) { echo "Cannot open file ($file)"; exit; } for ($i = 0; $i <= 18; $i++) { fwrite($handle, $log[$i]); unset($log[$i]); } $i = 0; while (count($log) > $limit) { unset($log[$i]); $i++; } foreach ($log as $line) { fwrite($handle, $line); } fclose($handle);   }   ?>[/code] Don't beg for code in the future please.
  9. Why are you setting $dir to be something other than $folder?  Also, I wouldn't include the image file.  If you are returning an image to the browser, then just use file_get_contents and echo out the file. [code]<?php function dirlisting($folder){ if ($handle = opendir($folder)) { $num = 0; while (false !== ($file = readdir($handle))) { if ($file{0} != '.') { $files[$num] = $file; $num++; } } } $random = rand(0, (count($files)-1)); $ll = substr($files[$random], -1); if (substr($folder, -1) != "\\") { $folder .= "\\"; } if ($ll == 'g'){ header ('Content-type: image/jpeg'); echo file_get_contents($folder . $files[$num]); } else { header ('Content-type: image/gif'); echo file_get_contents($folder . $files[$num]); } } ?>[/code]
  10. rather than using the value property for the select box, use the text property, which will return the string displayed, rather than the value of the option selected for your javascript function.  However, when the script is posted, it should still return the proper value...unless you change it via javascript
  11. I use a php library named minixml to parse xml for my scripts: http://minixml.psychogenic.com/index.html If you are looking for a feed reader, then just do a google search.
  12. [code]UPDATE phone_tariffs SET Name = 'newname', Tariff = 'newtariff', Image = 'newimage WHERE idfield = 'identifier'[/code] idfield would be your primary key.
  13. [code]UPDATE tablename SET field1 = 'newvalue', field2 = 'newvalue' WHERE idfield = 'identifier'[/code] http://dev.mysql.com/doc/refman/5.1/en/update.html
  14. This is a javascript question I believe. This page should help you with generating the JS for a popup: http://javascriptkit.com/popwin/index.shtml
  15. Just put the date you're wanting into the value of the select option: [code]<?php list($y,$m,$d) = explode("-",date("Y-m-d")); $daysValue = array(); for ($i=0;$i<=6;$i++) { $n = mktime(0,0,0,$m,$d+$i,$y); $daysValue[date("Y-m-d", $n)] = date("l", $n); } echo ' <select name="night" onchange="Fill_Sub()" style="width:150px; height:17px; font-family:tahoma; font-size:10px; color:#9A400C "> <option value="">Select one</option>'; foreach ($daysValue as $key => $value) { echo  ' <option value=' . $key . '>' . $value . '</option>'; } echo "</select>"; ?>[/code]
  16. use the file function (http://www.php.net/file). It reads the file into an array, which you can then parse line by line.
  17. Use the CSS properties margin and padding:
  18. can you post the first 5 or so rows of html?
  19. [code]<?php $result = mysql_query("SELECT * FROM kanji.kanji ORDER BY lesson ASC, kanji_id ASC") or die(mysql_error()); $x = 1; $prevlesson = ""; echo ' <table border="1"> <tr>'; while($row = mysql_fetch_assoc($result)){ echo ' <td align="center"><a href="explain.php?kanji_id=' . $row[kanji_id] . '">' . $row[kanji] . '</a></td>'; if ($row[lesson] != $prevlesson){ while ($x <= 15) { echo "<td>&nbsp;</td>"; $x++; } $x = 1; echo ' </tr> <tr>'; } else { $x++; } $prevlesson = $row[lesson]; } echo " </tr> </table>"; ?>[/code]
  20. [code]<?php $moo = array ( 0 => 'hey.txt', 1 => 'logo.gif', 'Wow' => array ( 0 => 'cool.gif', 1 => 'Saved Game', 2 => 'OK!' ,), ); $cow = array ( 0 => 'logo.gif', 'Wow' => array ( 0 => 'cool.gif', 1 => 'Saved Game' ), ); $diff = array_intersect($cow, $moo); $iff = array_diff($moo, $cow); echo '<pre>'; print_r($moo); echo '<br />'; print_r($cow); echo '<br />'; print_r($diff); echo '<br />'; print_r($iff); ?>[/code] Results in: [code]Array (     [0] => hey.txt     [1] => logo.gif     [Wow] => Array         (             [0] => cool.gif             [1] => Saved Game             [2] => OK!         ) ) Array (     [0] => logo.gif     [Wow] => Array         (             [0] => cool.gif             [1] => Saved Game         ) ) Array (     [0] => logo.gif     [Wow] => Array         (             [0] => cool.gif             [1] => Saved Game         ) ) Array (     [0] => hey.txt )[/code] Which appears to work to me.
  21. What are you searching?  Don't say album titles either......I know that. What we need to know is, are you using a database, if so, which one?  Are you useing a text file with all of the information stored in a formatted way?  Are the names of albums scattered hopelessly across your file system so that the server must search through entire directories to find a particular file name? If you are using MySQL, here is a link to the phpfreaks.com search tutorial... http://www.phpfreaks.com/tutorials/129/0.php I think this is a record, I've posted that link 4 times now in I think three days.
  22. Most likely the delay that your experiencing is due to network latency.  It takes time for the browser to send the request to your server, then your server to process it and return a value, then the browser to receive the image file and display it.
  23. Use array_intersect and/or array_diff http://www.php.net/array_intersect http://www.php.net/array_diff
  24. start with strtotime, if that won't work with the full string, then you will have to break it apart into something that it will accept. http://www.php.net/strtotime
  25. Holy crap, that's a lot to say about a not-too-complicated subject. Anyway, I think it's great that you posted it, and I'm sure it will help some people.  However, I don't think that this particular forum is the place.  One, it's not a request for help, so a lot of people will get upset about that, and two, there is already two places for tutorials:  the main phpfreaks.com tutorial repository, and the tutorial/faq repository in the forums (http://www.phpfreaks.com/forums/index.php/board,41.0.html).  You can usually get your stuff posted there just by asking one of the mods about it. Posting it here also means that it will fall down the pages quickly, and most people aren't going to do a search for a tutorial in a general help forum.
×
×
  • 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.