
dink87522
Members-
Posts
142 -
Joined
-
Last visited
Never
Everything posted by dink87522
-
?
-
$query = "SELECT * FROM Companies WHERE owner = '$userName'"; $result = mysql_query($query) or die("Error: " . mysql_error()); $count = mysql_num_rows($result); echo("Count: $count<p>"); $result = mysql_query("SELECT name FROM Companies WHERE owner = '$userName'") or die("Error: " . mysql_error()); $result = mysql_fetch_row($result); for ($i=0; $i<=$count; $i++){ // $i<=$count means do while $i is less than or equal to $count /$companyName[$i] = $result[$i]; echo("$i: $companyName[$i]<br />"); echo("$i: $a<br />"); } I am trying to check the number of entries of company names the user has in the table Companies. I am then trying to use a for loop to loop through and store each of those names into an array. It doesn't work and I don't know why, can anyone see my problem?
-
<form name="statCompany" method="post" action="statCompanies.php"> <label>Sort by:</label> <select name='criteria'> <option value='nameAsc'>Name (Asc)</option> <option value='nameDesc'>Name (Desc)</option> <option value='ceoAsc'>CEO (Asc)</option> <option value='ceoDesc'>CEO (Desc</option> <option value='moneyAsc'>Money (Asc)</option> <option value='moneyDesc'>Money (Desc)</option> </select> <label><button type="submit" name="sort" id="sort" value="Sort"> Sort </button> </form> How can I dynamically set one of these in the drop down list as the default? I.e. the top one is fine originally, but then after the user has selected the third one say and the page reloads, I want the third one to be the default selected then (suing PHP if possible).
-
$date = time(); $query = "SELECT * FROM experience_process"; $result = mysql_query($query) or die("Error: Could not be completed." . mysql_error()); $process = mysql_fetch_assoc($result); $count = mysql_num_rows($result); echo("<br />date: $date"); echo("<br />Count: $count"); do { // Keeps getting the next row until there are no more to get $user = $row['user_name']; echo("<br />User: $user"); } while ($row = mysql_fetch_assoc($result)); I want to loop through all the users (and echo their name). The above code does not get the first result from the table (so I stopped using a loop and tried a do loop, although same thing), what do I need to do to change this?
-
I am trying to follow the tutorial found at http://www.php-mysql-tutorial.com/wikis/php-tutorial/admin-page-for-content-management-system-cms.aspx and like one of the user's in the comments of that tutorial, my edit data is not being saved. I try to edit an article although the edit is not saved. The MYSQL user has all permissions to the database. Anyone know why it may not be working?
-
Thanks, that is a very handy tip
-
The below code gives the error "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/obama/public_html/picks/loginProcess.php on line 20" Why, or what do I need to do to avoid this/fix it? <?php // loginProcess.php session_start(); $user = $_POST["user"]; $pass = $_POST["pass"]; $_SESSION['login'] = 0; $servername = "localhost"; $username = "*******"; $password = "********"; $dbCon = mysql_connect($servername, $username, $password); if (!$dbCon) { die(); } mysql_select_db("*****") or die(mysql_error()); $sql="SELECT * FROM users WHERE userName='$user' and passwod='$pass'"; $result=mysql_query($sql); $count = mysql_num_rows($result); if($count == 1){ $_SESSION['user'] = $user; $_SESSION['login'] = 1; echo("logged in"); }else{ $_SESSION['error'] = "Invalid username or password. Please try again."; echo("not logged in"); } ?>
-
Thanks, as usual I was trying to over-complicate it.
-
This should be simple, but I can't get it to work now. $score = $_COOKIE["score"]; if(isset($_COOKIE["hsPrev"])){ $hsPrevious = $_COOKIE["hsPrev"]; $hsPreviousSort = explode(",", $hsPrevious, 6); }else{ $hsRecord = $score; setcookie("hsPrev", $hsRecord); } the above doesn't work and the code I had which was mostly working is gone now. $score will equal say 5. This score is to be stored in the cookie hsPrev. Say the next score = 2. Should be stored/apended to the end of the cookie also i.e. "5,2" I only want their to be 5 scores in the cookie (i.e. say "4,2,12,3,9"), the 5 latest, so the older scores should be removed and this is predominantly where I am having trouble. Can someone help me with this?
-
Searching string for entries and tabling those entries
dink87522 replied to dink87522's topic in PHP Coding Help
Thanks, that got me on the right track. -
I have a string that looks like "14, 1, 4, 5, 16, 17, 2, 2, 5, 1, 5, 20, 5" etc but with many more characters (and it may end up with a few thousand characters to it in the end). Each character is between 1 and 20 (inclusive) and separated by ",". I need to search this string and count how many times each number occurs (i.e how many 1's, how many 2's ... how many 20's). I sort of got it working using a for loop and switch statement although it was rather obfuscated. What would be the easiest way to do this?
-
Okay, thanks for the help
-
mysql_select_db("amazon_Score") or die(mysql_error()); $query = SELECT ageGroup FROM Highscores WHERE ageGroup = "16-30"; $result = mysql_query($query) or die(mysql_error()); Why do I get a T string error (2nd line)? I want to select all the data from the column ageGroup whose value is equal to "16-30".
-
Hmm, still doesn't work. q2a prints "GrenadaDSt. George'sD0" while q0 prints "Array", q1 prints "Array" and q2 prints "Array" Sorry I am only a beginner at PHP.
-
I want it so that q0 prints "Grenada", q1 prints "St. George" and q2 prints "0". Currently they are all printing empty.
-
$q20 = $_SESSION['q20']; echo("q2a: $q20"); for ($i = 0; $i < 3; $i = $i + 1){ $q20Split = array_slice(explode("D", $q20), $i, 1); $question20[i] = $q20Split; } echo("q0: ".$question20[0]); echo("q1: ".$question20[1]); echo("q2: ".$question20[2]); q2a prints "GrenadaDSt. George'sD0" q0, 1, 2 do nit print.
-
My code on one page is: $_SESSION['q20'] = $countries[$rndWork]."D".$answer."D".$answer_result; and on the next page is: $q20 = $_SESSION['q20']; for ($i = 0; $i < 3; $i = $i + 1){ $q20Split = array_slice(explode("D", $q20), i, 1); $question20[i] = $q20Split; } ?> however I get the following error which I have never seen before: Warning: array_slice() expects parameter 2 to be long, string given in /home/public_html/geographytrainer.com/hsDis.php on line 31 Warning: array_slice() expects parameter 2 to be long, string given in /home/public_html/geographytrainer.com/hsDis.php on line 31 Warning: array_slice() expects parameter 2 to be long, string given in /home/public_html/geographytrainer.com/hsDis.php on line 31
-
Title should read descending, not ascending sorry.
-
I am using $query = "SELECT * FROM Highscores ORDER BY score DESC"; to select data from a table called highscores and a field called scores. I wish to sort the data in descending order (i.e. highest value first). It sort of works, ie.: it does: 9 8 7 6 5 4 3 2 13 12 11 1 etc, how do I make 11, 12, 13 show at the top?
-
Thanks for the excellent explanation, that cleared up a couple of things and it now works!
-
???