GingerRobot
Staff Alumni-
Posts
4,082 -
Joined
-
Last visited
Everything posted by GingerRobot
-
Well, as described on the manual, mysql_fetch_assoc returns an associative array of the current row and moves the internal pointer ahead. So, by using a loop like the one i posted, you loop through each row returned from your query. This allows you to create an array of all the existing repNumbers
-
Either create another page, for example edit.php, to handle the editing of posts, rather than using an action defined in your URL for the same page. Or, change what is output to the browser dependant on the action. For example: <?php if($_GET['action'] !='edit'){ //show normal page content...in your case, the news }else{ //show the form to edit the post } ?> That way, if the action is to edit, all that would be shown would be the edit form, so it would be at the top of your page.
-
Take a look at this class created by one of the moderators from this site, Barand: http://members.aol.com/barryaandrew/baaChart/baachartguide.html
-
Ok, well what i suggested should work, although, on second thoughts, i would imagine it might be more efficient to generate an array of the rep numbers that already exist, and loop untill you find a number thats not in that array: <?php $query = "SELECT repNumber FROM salesrep"; $result = mysql_query($query) or die('Query failed: '.mysql_error()); $numbers = array(); while($row = mysql_fetch_assoc($result)){ $numbers[] = $row['repNumber']; } $rand = mt_rand(1,10000); while(in_array($rand,$numbers)){ $rand = mt_rand(1,10000); } //insert using $rand ?> Otherwise you could end up doing quite a few queries, at least with this way, it'll only be the one.
-
Something like: <?php $num = 1; while($num != 0){ $rand = mt_rand(1,10000); $sql = mysql_query("SELECT count(*) FROM salesrep WHERE repNumber=$rand"); $num = mysql_result($sql,0); } echo 'Unique redNumber: '.$rand; ?> However, wouldn't you be better just using an auto-increment field to have a unique number for your reps?
-
Work fine in firefox for me. Do you have javascript disabled in firefox?
-
Basically, you need to validate all user input to make sure that a malicious user can't do damage to your database, or get information that they shouldn't have access to. The mysql_real_escape_string() function is a good place to start. If you're interested in how a user might do damage, google SQL injection.
-
Try doing it like: $hitpoints = $hitpoints/100*74; Edit: Also, you might only want whole numbers. If so, use the round() function: $hitpoints = round($hitpoints/100*74);
-
Take a look at the md5() function. The idea is that whever you go to do something with a password, you apply the md5() function to it, to hash the string. So, when someone registers, the password you store is the hashed version. When someone logs in, you hash the password they provide, and check this against the password stored in the database.
-
Try: $arr = $db->getArray("SELECT * FROM table WHERE name LIKE '%$n%' AND company LIKE '%$c%' AND category_id = 81"); If you are searching for a string, you have to enclose the string in quotes.
-
Any particular reason? Its usually a bad idea to have case sensitive usernames. As for passwords, yes, they should be case sensitive, but you should also hash them first which would resolve that issue.
-
Well, firstly you're using the assignment operator inside your if statement (single equals sign), which is always going to evaluate to true. However, you're also setting the value of $_SESSION['password'] to 0 right before you check it, so its never going to work. This should do the trick: <?php session_start(); if($_SESSION['password'] == 0) { header("location: login.php"); } ?>
-
Its as simple as: unset($array);
-
You should get used to using the square brackets for the string offset. Take a look at the minutes from the php meeting with regard to php 6. Curly braces wont work in php 6 for this sort of thing. http://www.php.net/~derick/meeting-notes.html#cleanup-for-vs Edit: Just noticed that two people from yahoo were present at the meeting..a quick google confirms that yahoo uses php as their backend. Quite surprised to see that!
-
Not possible unless everything i've ever read about php tags was rubbish
-
Try: <?php if($lan==='sp'){ $separate=explode(' ',$word); foreach($separate as $v){ $getWord="SELECT Sp FROM tra_translator WHERE En='$v'"; $query=mysql_query($getWord)or die(mysql_error()); $wordNum=mysql_num_rows($query); if($wordNum>0){ $word=mysql_fetch_array($query); echo $word['Sp']; }else{ echo $v; } } }else{ echo $v; } } ?> You were echoing $word. You should have been echoing $v, since this is the word being searched for in each iteration of your loop. Edit: The reason why it displayed array, is because your defined $word as an array: $word=mysql_fetch_array($query);
-
Not on my calculator. The way Barand showed was correct.
-
Use the implode() function on an array to create a list of possible values to use with the IN syntax in your query: <?php $cats = array('Aprilia', 'Ducati', 'Honda', 'Suzuki', 'Yamaha');//an array of the possible categories. I assume this might depend on form input. $data1->q("SELECT * FROM categories WHERE cat_name = IN(."implode(',',$cats)".) ORDER BY cat_name asc"); ?>
-
You dont. Take a look at some pagination tutorials. You repeat the query on each page, using differant parameters for the LIMIT clause based on the page number. Of course, you'll need to pass what is being searched for from page to page to repeat the query though
-
[SOLVED] xampp help for mysql - anyone know xampp well?
GingerRobot replied to FB's topic in MySQL Help
Well yeah, that works if you installed phpMyAdmin, or took the easy option(which i did) and installed WAMP which does that for you -
You'll need the eval() function to evaluate any php code. However, if the code is not even making it to the database, you have other problems and we might need to see some code. Edit: SA is quite possibly right. I assumed you are using your own CMS however.
-
Try: if ($_GET['justnews'] == "deletenews"){ mysql_query("DELETE FROM usernews WHERE id = '".$_GET['id']."'") or die(mysql_error()); }elseif($_GET['justnews']== "deleteall"){ mysql_query("DELETE FROM usernews WHERE user = '$info[id]'") or die(mysql_error()); } Unless you have register_globals turned on, then $justnews and $id are undefined. You need to retreive them from the $_GET array.
-
image gallery help... need 'previous' and 'next' commands
GingerRobot replied to Rogue3's topic in PHP Coding Help
If you want someone to do something for you, head over to the freelance forum. If you have a go at it yourself, and get stuck, then feel free to ask for some help here. -
If you take a look at the documentation for the readdir() and the opendir() functions, there are some examples of how to do this.
-
Is it "wrong" to piggyback off someone's wireless network?
GingerRobot replied to a topic in Miscellaneous
There have actually been a few cases(albeit very few and isolated) here in the UK of people successfully pressing charges against someone using their internet without permission.