Jump to content

jcd

Members
  • Posts

    28
  • Joined

  • Last visited

    Never

Everything posted by jcd

  1. Should this be $_POST['search'] ? $str = htmlspecialchars($_POST['str'])
  2. I think I was on the wrong track with recursion (just sent my brain round in circles), but I don't see how joins will help you since you only have one table you're extracting data from. But I'm new to PHP/SQL myself so I could be wrong there too. Meanwhile give this a try. It's not exactly pretty, but it should do what you want, fast. <?php $q = 'SELECT * FROM weapons ORDER BY class'; $rh = mysql_query($q); $num_rows = mysql_num_rows($rh); for ($i = 0; $i < $num_rows; $i++) { if (!mysql_data_seek($rh,$i)) { die("Could not seek to row $i."); } $row = mysql_fetch_assoc($rh); if ($i == 0) { $current_class = $row['class']; outer_table($row,$i,$num_rows); continue; } if ($current_class == $row['class']) { print_row($row,$i,$num_rows); continue; } else { $current_class = $row['class']; close_tables(); outer_table($row,$i,$num_rows); continue; } } function outer_table($row,$counter,$total_rows) { echo '<table><tr><th>',$row['class'],'</th></tr><tr><td> <table class="instable"><tr><th width="35px">Image</th> <th>Name</th><th width="20px">Level</th> <th width="60px">Durability</th> <th width="60px">Attack</th></tr>'; print_row($row,$counter,$total_rows); } function print_row($row,$counter,$total_rows) { echo '<tr> <td width="35px"><img src="'.$row['image'].'" /></td> <td align="left">'.$row['wname'].'</td> <td width="20px">'.$row['wlevel'].'</td> <td width="60px">'.$row['wdurability'].'</td> <td width="60px">'.$row['wattack'].'</td> </tr>'; if ( $counter + 1 == $total_rows) { close_tables(); } } function close_tables() { echo '</table></td></tr></table>'; } ?>
  3. Try this. It works. But it queries the database each time it makes a new table so is not very effecient. i'm sure it can be done with one query using recursion. <?php $q1 = 'SELECT DISTINCT class FROM weapons ORDER BY class'; $rh1 = mysql_query($q1); while ($row = mysql_fetch_row($rh1)) { echo '<table><tr><th>',$row[0],'</th></tr><tr><td> <table class="instable"><tr><th width="35px">Image</th> <th>Name</th><th width="20px">Level</th> <th width="60px">Durability</th> <th width="60px">Attack</th></tr>'; $q2 = "SELECT * FROM weapons WHERE class='$row[0]'"; $rh2 = mysql_query($q2); while ($row = mysql_fetch_assoc($rh2)) { echo '<tr> <td width="35px"><img src="'.$row['image'].'" /></td> <td align="left">'.$row['wname'].'</td> <td width="20px">'.$row['wlevel'].'</td> <td width="60px">'.$row['wdurability'].'</td> <td width="60px">'.$row['wattack'].'</td> </tr>'; } echo '</table></td></tr></table>'; } ?>
  4. jcd

    Screen Scrape

    Your IF condition (in bold above) will only be positive and come into play at line 4:. Since this is inside a foreach loop, line 4 is the only line that exists, therefore your preg_match will never find the *in route* which is on line 5.
  5. Try: preg_match_all('/(?<=\[url\])[^\[]+?(?=\[\/url\])/i',$text,$matches);
  6. jcd

    New to Regex

    I've just realised the method above is a silly way of doing it (im new at this...). If you do want to combine them better to do: echo preg_match('%\A(\d+|[A-Za-z]+)\z%', $subject) ? 'TRUE' : 'FALSE';
  7. jcd

    New to Regex

    Are you looking for 1 regex which will allow both? If so this will do it I think: $subject = 'asdasdadrg'; echo preg_match('%\A(\d)?(?(1)\d*|[A-Za-z]*)\z%', $subject) ? 'TRUE' : 'FALSE';
  8. I was curious, are you putting the NODE_PATH in the db manually, or generating them with code?
  9. I use DevPHP. I've tried all the free editors suggested in this thread, but I'll be sticking with DevPHP because it has the most intelligent syntax highlighter. http://devphp.sourceforge.net/
  10. I've just noticed that your echo doesn't query the database. You are at the moment echoing normal $variables which you set at the beginning of the script, but did not change..so of course the echo will not change. You need something like $query = "SELECT owner, trade_id FROM usersitems2 WHERE ...(unique id)"; $rh = mysql_query($query); $results = mysql_fetch_rows($rh); echo 'Owner: ', $results[0], ' Trade id: ', $results[1]; Do that after every testing query to see if the values updated as you expected.
  11. To be fair, that's a very clear error message. Have you tried scanning around line 44 for a missing ";" which it says it's expecting?
  12. Put an echo statement after each of your testing queries. This will help you see where you're going wrong. Paste the results of the echos here.
  13. The runt.bat file would stop your windows defender & firewall services if executed.
  14. The first query sets trade_id to blank yes? So when the second query is executed it doesn't find a "WHERE trade_id = '$trade_id'", so no update is made.
  15. I think (but not sure) its because: Lets say your test string is 'ab'. After the first match "a" is replaced the string has now changes to '<div class="a"></div>b'. Now when it looks the next matches to replace it will the letters in teh div/class tag and replace them too. View the html source of the output to see all the mangled divs.
  16. http://www.regular-expressions.info/javascriptexample.html Works fine with the above expression. Insert without the / at the start and end.
  17. Er, looks like I put a stray www in there. Change to: $str = preg_replace('/\b((?:[a-z0-9+.-]+:\/\/)?(?:\w+\.)+\w{2,6}\S*)/','<a href="$1">$1</a>',$str); Tried to edit above post but the edit button has disappeared...
  18. This does the trick I believe: <?php $str = "dss s sd s www.site.com but may not work"; $str = preg_replace('/\b(?:[a-z0-9+.-]+:\/\/)?((?:www\.)(?:\w+\.)+\w{2,6}\S*)\b/','<a href="$1">$1</a>',$str); echo $str; ?>
  19. Even though though the above match includes numerical digits, once you execute the preg_replace, the digits will not be replaced only the " " will. But if you really want just the " " to match you can do: (?<=\d) (I'm new to RegExps, sorry if my try gets you in more problems )
  20. Here is one way you could implement the suggestions above. It's only for demonstration purposes, I would put the array near the top of the actual document. <select size='1' name='occupation'> <?php $occupation_list = array('All','Acrobat','Clown','Juggler','Sword Swallower','Wrestler'); $occupation = $_GET['occupation']; foreach ($occupation_list as $occ) { echo "<option value=\"$occ\""; if ($occ == $occupation) { echo ' selected="selected"'; } echo ">$occ</option>"; } ?> </select>
  21. Thanks once more. It took some googling but the script works great
  22. Thanks, I haven't got to looking ahead yet, although I had heard of it. What tool did you use to break down the regexp?
  23. Thanks. I don't understand why it works though. I have some reading to do
  24. Yes I forgot about general whitespace, so I suppose the above regexp is now /\s{2,}/ ? But the problem is that now "+" and "=" etc are allowed. I can't figure out how to combine above regexp with mine which only allows \w and single space characters.
×
×
  • 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.