PHP - Noob - Help With Small Php Program (arrays And Sorting)
I am having trouble with a small PHP program. I have to load item and amount data from table cells into an array, and then be able to sort and reverse sort the items in the cells. I also have to track the errors when non-numeric data is entered a s an amount, and total the numeric amounts (These parts I think I have coded correctly.).
I am having trouble with the array part. I don't think item values are being loaded into the array. I debugged it as much as I could. My code is here-- http://pastie.org/1084621 . I am completely new to this, having only done little PHP/JavaScript programs like this for some classes in the last few months. Any help would be greatly appreciated. Similar TutorialsI have a table called members. Each member located within the members table has a unique id field called ID I have a second table called user_program in which also contains the id number of the member from the members table Each member has 5 entries in the table user_program using the field called program_id which has a value of either 1, 2, 3, 4 or 5 Additionally there is a user_status field within the same user_program table The value of user_status is either Active, Comped, Temp-Comped or Unpaid What I am trying to do is determine is which is the highest program_id that a specific member holds a user_status equal to Active and then assign the program_id to a variable. Here is the structure of the user_program table user_program_id program_id user_status auto incrementing number 1 Active auto incrementing number 2 Active auto incrementing number 3 Unpaid auto incrementing number 4 Unpaid auto incrementing number 5 Unpaid Here is the code I have been working with trying to figure it out.....any help would be appreciate :-) Code: [Select] $r1 = mysql_query("SELECT * FROM members WHERE Username='".$_SESSION['loggedin']."'"); $buffer_r1 = mysql_fetch_assoc($r1); $usrid = $buffer_r1['ID']; $r2 = mysql_query("SELECT * FROM user_program WHERE ID='".$usrid."'"); $buffer_r2 = mysql_fetch_assoc($r2); $level_id = $buffer_r2['program_id']; $user_status = $buffer_r2['user_status']; $grace_start = $buffer_r2['grace_start']; while(!$user_status ==("Comped" || "Unpaid")){ if($level_id == "1" && ($user_status == "Active")){ $level_name = "Professional"; }elseif($level_id == "2" && ($user_status == "Active")){ $level_name = "Gold"; }elseif($level_id == "3" && ($user_status == "Active")){ $level_name = "Diamond"; }elseif($level_id == "4" && ($user_status == "Active")){ $level_name = "Platinum"; }elseif($level_id == "5" && ($user_status == "Active")){ $level_name = "Elite"; } } I know the code within the while state is correct to assign the end variable, but my problem is that its only looking at the first program_id returned from the database that matches the user ID and does loop through the rest of the entries for that person. Thanks in advance :-) I have a website that I have curled some data from and gotten the data I want. It is one large array. The variable is called $ten_pireps. For clarity I am only posting the first 8 keys=>value pairs. The array repeats the info every 8 keys. ending with key [79]. Array ( => ET20029 [1] => EAL391 [2] => ESKN [3] => EETN [4] => E35 [5] => 0.8 [6] => 284 [7] => 01/02/2011 I need to iterate through this 79 key array and place keys thru [7] into another variable array called $flightinfo1, keys [8] thru [15] into $flightinfo2, etc..... finish with the final array $flightinfo10. Secondly, I am trying to name the keys of the new 10 smaller seperate arrays with key names [Flight_Num] [Call_Sign] [Dep_Icao] [Arr_Icao] [Equip] [Flt_Time] [Flt_Distance] [Date] being the same for each array. Ultimately I will be inserting this into a db. I suck with arrays, and have tried to modify code snippets and have had no success. Here is something I was trying but just could echo anything out that made sense. foreach ($ten_pireps as $key=>$value) { } for ($i=0,$j=1;$i<count($ten_pireps); $i+=8,$j++) { $flight="flightinfo"; $flightsql="$flight$j"; // create new variable name array as it iterates $flightsql[Flight_Num] = $ten_pireps[$i]; $flightsql[Call_Sign] = $ten_pireps[$i+1]; $flightsql[Dep_Icao] = $ten_pireps[$i+2]; $flightsql[Arr_Icao] = $ten_pireps[$i+3]; $flightsql[Equip] = $ten_pireps[$i+4]; $flightsql[Flt_Time] = $ten_pireps[$i+5]; $flightsql[Flt_Distance] = $ten_pireps[$i+6]; $flightsql[Date] = $ten_pireps[$i+7]; // unfinished cause it is wrong!!!! } Thanks for the read - Nacman Hello,
I've been struggling to get array_multisort to work...
If I have this array output...
I'd like to sort on the product sub-array.
The array is called orders and that number 15 is the specific order id.
Array ( [15] => Array ( [clientId] => 1 [clientName] => Bob [o_date] => 2014-01-02 [o_number] => 1 july-append [o_notes] => order on 1 july-append [i_date] => 2014-01-17 [i_number] => 18072014-append [i_notes] => invoiced on 18 july 14 -append [products] => Array ( [0] => Array ( [id] => 37 [prod_id] => 1 [product] => door [qty] => 2 [cost] => 12.121 ) [1] => Array ( [id] => 38 [prod_id] => 2 [product] => window [qty] => 3 [cost] => 22.5 ) [2] => Array ( [id] => 36 [prod_id] => 3 [product] => chair [qty] => 1 [cost] => 300 ) ) ) )So, I've tried a number of variations of this... array_multisort($orders[$theOrder]['products'], SORT_DESC, SORT_NUMERIC, $orders[$theOrder]['products'], SORT_ASC, SORT_STRING); array_multisort($orders[$theOrder]['products']['id'], SORT_DESC, SORT_NUMERIC);etc. etc. - but I seem to get no-where. Can some-one kindly point out my error, please? Thank you. Hi everyone I have 2 queries which are pulling out results into arrays I think they are right I then insert a new column into each array one with [typeofdonation] as "cash" and one as "card" this is to be used later when outputting the results I then need to combine the 2 arrays into 1 array and then sort the combined array by date showing the latest ones first I then need to output the top 3 results The way the results are outputted is dependant on what [typeofdonation] is as they are outputting and styled differently Here is my code below I have got upto the combining the 2 arrays but am having difficulty doing this Once I have done this I then need to sort the results but I think my code I have tested on each array works ok and so will work once I have the combined array. Final part I am not sure on how to find and use what is in [typeofdonation] to determine the styling and way each of the 3 results is outputted Thankyou in advance for everyone who can hopefully help me in the right direction Peter Code: [Select] <b>Card Donations</b><br><br> <?php $getcarddonations = $wpdb->get_results("SELECT wp_supporters_donations.SFMemberNumber, wp_supporters_donations.KickbackAmount, wp_supporters_donations.MerchantName, wp_supporters_donations.SpendDate from supporter_2_cause RIGHT JOIN wp_supporters_donations ON supporter_2_cause.supp_id=wp_supporters_donations.SFMemberNumber WHERE supporter_2_cause.caus_id = '54' ORDER BY wp_supporters_donations.SpendDate"); //UNION SELECT id, amout, cause, date FROM cashdepo WHERE cause='Lisas charity' AND status='2' ORDER BY id DESC foreach($getcarddonations as $getcarddonations){ $i = 0; while($i < 100) { $data[$i]['member'] = $getcarddonations->SFMemberNumber; $data[$i]['ammount'] = $getcarddonations->KickbackAmount; $data[$i]['merchant'] = $getcarddonations->MerchantName; $data[$i]['date'] = $getcarddonations->SpendDate; $data[$i]['typeofdonation'] = 'card'; $i++; } } function compareItems($a, $b) { if ( $a->date < $b->date ) return -1; if ( $a->date > $b->date ) return 1; return 0; // equality } uasort($data, "compareItems"); print_r( $data ); ?> <br><br><br><b>Cash Donations</b><br><br> <?php $getcashdonationsdb = $wpdb->get_results("SELECT * FROM cashdepo WHERE cause='Lisas charity' AND status='2' ORDER BY id DESC"); foreach($getcashdonationsdb as $getcashdonationsdb){ $i = 0; while($i < 11) { $dataa[$i]['member'] = $getcashdonationsdb->id; $dataa[$i]['ammount'] = $getcashdonationsdb->amout; $dataa[$i]['merchant'] = $getcashdonationsdb->cause; $dataa[$i]['date'] = $getcashdonationsdb->date; $dataa[$i]['typeofdonation'] = 'cash'; $i++; } } uasort($dataa, "compareItems"); print_r( $dataa ); ?> <br><br><br> <b>Combined</b><br><br> <?php $datar1 = ($data); $datar2 = ($dataa); $finalarray = array_combine($datar1, $datar2); //sort uasort($finalarray, "date"); //Print the output print_r($finalarray); ?>
For example with an IDE to run a program is there a way to put some code in the path and let it tell me where it came from like a referral? $ref = $_SERVER['HTTP_REFERER']; echo("$ref<br>"; Result: https://www.mydomain.com/wp-admin/admin.php?page=lambo As you can clearly see the page that we have entered the code in is referred by the URL here. It tells me that it was last at a word press page /wp-admin/admin-php and I can go to that page and it will be the last page it was at.. So bottom line then if i add this code to the admin page and click the same button i had before.. it will tell me the file that called out the admin page. Baslcaly I am looking for ideas on how to track the page i am now all the way back to the page with the button on it and all intermediate pages that it passes thru to get to the final destination. It seems that to succesfully troubleshoot a fault is to follow the path of the entire job and see if any breaks... Any thoughts or suggestions on how to best do this would greatly be appreciated.
Please bear with me. In an html file there is an <!-- BEGIN poll --> ..... <!-- END poll --> I need to draw a separation hr between all rows escept the first one. I believe I need a counter. Please show me how to do this. Thank you. I have this thing that i am trying to make but i cant get it to work.. can anyone help? Code: [Select] function sql_read( $dbname,$dbusername,$dbpassword ) { $names = array(); $password = array(); $connect = @mysql_connect("mysql11.000webhost.com",$dbusername,$dbpassword) or die("Could Not Connect"); @mysql_select_db ($dbname) or die("Could not find DataBase"); $query = mysql_query("select * from users"); $numrows = mysql_num_rows($query); if ($numrows > 0){ while($row = mysql_fetch_assoc($query)){ $names[] = $row["uname"]; $password[] = $row["password"]; $id = $row["id"]; } $return = array($names,$password,$id); }else{ $return = array(); } return $return[]; } $names = array(); $names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0]; The error i get is Code: [Select] Parse error: syntax error, unexpected '[' in /home/a5480952/public_html/sql/index.php on line 28 Line 28 is "$names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0];" Please help... i REALLLLD need help with this.. ask questions if you want to know more about what i am trying to do... thanks! I'm having troubling with trying to create a function to spit out a single array with the following array. I can write it in a away that looks through the arrays manually. the results i am trying to generate is that each item in generated array. Array to convert array( "account" => array( "login", "register", "logout", "edit", ), "p" => array( "report", ), "array1.0" => array( "array2.0" => array( "array3.0", "array3.1 ), "array2.1", ), generating the array will look like this
Array ( [0] => account [1] => account/login [2] => account/register [3] => account/logout [4] => account/edit [5] => p [6] => p/report [7] => array1.0 [8] => array1.0/array2.0 [9] => array1.0/array2.0/array3.0 [10] => array1.0/array2.0/array3.1 [11] => array1.0/array2.1 ) The idea is that id generates a single array with combined labels and arrays inside, etc. I just can't figure out how to create a script that will create this array even If I add a new value or array.
I have two arrays, both with the same key values. I'd like to combine them. So for instance... Code: [Select] <?php $array1['abcd'] = array( 'value1' => "blah", 'value2' => "blahblah"); $array1['efgh'] = array( 'value1' => "ha", 'value2' => "haha", 'valuex' => "xyz"); $array2['abcd'] = array('value3' => "three", 'value4' => "four"); $array2['efgh'] = array( 'value3' => "hohoho", 'value6' => "six6"); function combine_arrays($array1,$array2) { //*combining* return $single_array; } echo "<pre>"; print_r(combine_arrays($array1,$array2)); echo "</pre>"; /* would produce ['abcd'] = ( 'value1' => "blah", 'value2' => "blahblah", 'value3' => "three", 'value4' => "four" ) ['efgh'] = ( 'value1' => "ha", 'value2' => "haha", 'valuex' => "xyz", 'value3' => "hohoho", 'value6' => "six6" ) */ ?> What's the easiest way to do this? Hi I need to include a exe program in a website. The only file of this program is the .exe file. It has a couple of textboxes, and when you insert values in these boxes and submit it gives an text output in the same window. Is there a way in php that I can take in values from an html form and insert it into this programs form? And then how can I read its output using php? Or is there another web-based language that I should rather use? Your help would be appretiated! C I stumbled across this site after being slammed hard elsewhere for being a novice and really not knowing what I am doing. What I have read so far is more encouraging. I just wrote my first program in php and it is not working at all right now. All it keeps doing is opening window after window until I force the browser to close. I am using a Mac running Yosemite and using MAMP. Hopefully that is enough background.
I know this is an introduction area, so I will also post this in another forum in case this is closed for being off topic.
This is a login file to connect to the server:
<?php // login.php // Get connection information echo <<<_END <form method = "post" action = "login.php"> <pre> <input type = "text" name = "localhost" />host server<br /> <input type = "text" name = "username" />Username<br /> <input type = "text" name = "password" /><br /> <br /> <input type = "submit" value = "submit" /> </form> _END $db_server = sanitize_string($localhost); $db_username = sanitize_string($username); $db_password = sanitize_string($password); /* $user = 'root'; $password = 'root'; $db = 'rpsls'; $host = 'localhost'; $port = 3306; $link = mysql_connect( "$host:$port", $user, $password ); $db_selected = mysql_select_db( $db, $link ); */ mysql_connect($db_server, $db_username, $db_password) or die(mysql_error()); // Create rpsls table if it does not exist $tbl = "rpsls"; $query = "CREATE TABLE rpsls(human VARCHAR(10), computer VARCHAR(10), outcome VARCHAR(5), action VARCHAR(15)); INSERT INTO rpsls (human, computer, outcome, action) VALUES ("Rock", "Paper", "Lose", "Covers"); INSERT INTO rpsls (human, computer, outcome, action) VALUES ("Rock", "Scissors", "Win", "Crushes"); INSERT INTO rpsls (human, computer, outcome, action) VALUES ("Rock", "Lizard", "Win", "Crushes"); INSERT INTO rpsls (human, computer, outcome, action) VALUES ("Rock", "Spock", "Lose", "Vaporizes"); INSERT INTO rpsls (human, computer, outcome, action) VALUES ("Paper", "Rock", "Win", "Covers"); INSERT INTO rpsls (human, computer, outcome, action) VALUES ("Paper", "Scissors", "Lose", "Cuts"); INSERT INTO rpsls (human, computer, outcome, action) VALUES ("Paper", "Lizard", "Lose", "Eats"); INSERT INTO rpsls (human, computer, outcome, action) VALUES ("Paper", "Spock", "Win", "Disproves"); INSERT INTO rpsls (human, computer, outcome, action) VALUES ("Scissors", "Lizard", "Win", "Decapitates"); INSERT INTO rpsls (human, computer, outcome, action) VALUES ("Scissors", "Spock", "Lose", "Smashes"); INSERT INTO rpsls (human, computer, outcome, action) VALUES ("Scissors", "Rock", "Lose", "Crushes"); INSERT INTO rpsls (human, computer, outcome, action) VALUES ("Scissors", "Paper", "Win", "Cuts"); INSERT INTO rpsls (human, computer, outcome, action) VALUES ("Lizard", "Spock", "Win", "Poisons"); INSERT INTO rpsls (human, computer, outcome, action) VALUES ("Lizard", "Rock", "Lose", "Crushes"); INSERT INTO rpsls (human, computer, outcome, action) VALUES ("Lizard", "Paper", "Win", "Eats"); INSERT INTO rpsls (human, computer, outcome, action) VALUES ("Lizard", "Scissors", "Lose", "Decapitates"); INSERT INTO rpsls (human, computer, outcome, action) VALUES ("Spock", "Rock", "Win", "Vaporizes"); INSERT INTO rpsls (human, computer, outcome, action) VALUES ("Spock", "Paper", "Lose", "Disproves"); INSERT INTO rpsls (human, computer, outcome, action) VALUES ("Spock", "Scissors", "Win", "Smashes"); INSERT INTO rpsls (human, computer, outcome, action) VALUES ("Spock", "Lizard", "Lose", "Poisons");"; check_table($tbl, $query); // Create choices table if it does not exist $tbl = "choices"; $query = "CREATE TABLE choices(id SMALLINT, choice VARCHAR(10)); INSERT INTO choices (id, choice) VALUES (1, "Rock"); INSERT INTO choices (id, choice) VALUES (2, "Paper"); INSERT INTO choices (id, choice) VALUES (3, "Scissors"); INSERT INTO choices (id, choice) VALUES (4, "Lizard"); INSERT INTO choices (id, choice) VALUES (5, "Spock");"; check_table($tbl, $query); // Sanitize user input function sanitize_string($var) { $var = stripslashes($var); $var = htmlentities($var); $var = strip_tags($var); return $var; } function check_table($tbl, $query){ $db = new mysqli(...); $result = $db->query("SHOW TABLES LIKE "$tbl); if ($result->num_rows == 0){ mysql_query($query); } } ?>and this is the program: <?php // log into server and database require_once 'login.php'; $db_server = mysql_connect($db_hostname, $db_username, $db_password); if (!$db_server) die("Unable to connect to MySQL: " . mysql_error()); $conn = mysql_connect($db_server, $db_username, $db_password) or die(mysql_error()); $db_database = 'rpsls'; mysql_select_db($db_database) or die("Unable to select database: " . mysql_error()); // Start Game ready_to_play(); // Rock Paper Scissors Lizard Spock game function rock_paper_scissors_lizard_spock() { $human = human_play(); $computer = computer_play(); game_outcome($human, $computer); play_again(); // Start Game Function function ready_to_play(){ echo <<<_END <form method = "post" action = "rpsls.php"> <h2>Ready to play Rock, Paper, Lizard, Spock?</h2> <hr> <table> <tr> <td><input type = "radio" name = "ready" value = "Yes" />Yes</td> <td><input type = "radio" name = "ready" value = "No" />No</td> </tr> <tr> <td colspan = "2"><input type = "submit" value = "Play!" /></td> </tr> </table> </form> _END if ($ready == "Yes"){ $query = "CREATE TABLE gameResults ( games SMALLINT NOT NULL, win SMALLINT NULL, loss SMALLINT NULL, draw SMALLINT NULL, PRIMARY KEY (games))"; mysql_query($query); rock_paper_scissors_lizard_spock(); }else{ close_rpsls(); } } // Play Again // Start Game Function function play_again() { echo <<<_END <form method = "post" action = "rpsls.php"> <h2>Play Again?</h2> <hr> <table> <tr> <td><input type = "radio" name = "ready" value = "Yes" />Yes</td> <td><input type = "radio" name = "ready" value = "No" />No</td> </tr> <tr> <td colspan = "2"><input type = "submit" value = "Play!" /></td> </tr> </table> </form> _END if ($ready == "Yes"){ rock_paper_scissors_lizard_spock(); }else{ close_rpsls(); } } // Human Play Selection function human_play() { echo <<<_END <form method = "post" action = "rpsls.php"> <h2>Let's Play Rock, Paper, Lizard, Spock</h2> <hr> <table> <tr> <td><input type = "radio" name = "human" value = "Rock" />Rock</td> <td><input type = "radio" name = "human" value = "Paper" />Paper</td> </tr> <tr> <td><input type = "radio" name = "human" value = "Scissors" />Scissors</td> <td><input type = "radio" name = "human" value = "Lizard" />Lizard</td> </tr> <tr> <td colspan = "2"><input type = "radio" name = "human" value = "Spock" />Spock</td> </tr> <tr> <td colspan = "2"><hr></td> </tr> <tr> <td colspan = "2"><input type = "submit" value = "Play!" /></td> </tr> </table> </form> _END return $human; } // Computer Play Selection function computer_play() { $play = rand(1,5); $query = "SELECT choice FROM choices WHERE number = $play"; $computer = mysql_query($query); return $computer; } // Game Outcome Function function game_outcome($human, $computer) { $win = $loss = $draw = 0 if ($human == $computer){ echo "Draw<br />"; echo "We both played ".$human; $draw = 1; }else{ $query = "SELECT outcome, action FROM rpsls WHERE human = $human AND computer = $computer"; $results = mysql_query($query); $results2 = mysql_fetch_array($results); $outcome = $results2[0]; $action = $results2[1]; if ($outcome == "Win"{ echo "You Win!!!<br />" echo "Your ".$human. " ".$action." my ".$computer."<br />"; $win = 1; }else{ echo "You Lose/.<br /> echo "My ".$computer." ".$action." your ".$human."<br />"; $loss = 1; } } $query = "INSERT INTO gameResults VALUES".(NULL, '$win', '$loss', '$draw')"; mysql_query($query); } // Game Statistics Function function game_statistics () { $query = "SELECT * FROM gameResults"; $result = mysql_query($query); $rows = mysql_num_rows($result); $games = $rows; $win = $loss = $draw = 0; for ($index = 0; $index < $rows; ++$index){ $row = mysql_fetch_row($result); $win = $win + $row[1]; $loss = $loss + $row[2]; $draw = $draw + $row[3]; } echo <<<_END <table> <tr> <td>Games</td> <td>Win</td> <td>Loss</td> <td>Draw</td> </tr> <tr> <td>$games</td> <td>$win</td> <td>$loss</td> <td>$draw</td> </tr> </table> _END } // Print Statistics and close the game function close_rpsls(){ echo <<<_END <form method = "post" action = "rpsls.php"> <h3>Are you sure you want to quit?</h3> <hr> <table> <tr> <td><input type = "radio" name = "ready" value = "Yes" />Yes</td> <td><input type = "radio" name = "ready" value = "No" />No</td> </tr> <tr> <td colspan = "2"><input type = "submit" value = "Play!" /></td> </tr> </table> </form> _END if ($ready == "No"){ rock_paper_scissors_lizard_spock(); }else{ $query = "DROP TABLE gameResults"; mysql_query($query); } } // close connection mysql_close($conn); ?>Please forgive my novice errors and help me figure out what is wrong with this program. Thank you. Here is the contents of the error log: 141104 18:36:26 mysqld_safe Starting mysqld daemon with databases from /Applications/MAMP/db/mysql 141104 18:36:28 [Warning] Setting lower_case_table_names=2 because file system for /Applications/MAMP/db/mysql/ is case insensitive 141104 18:36:28 [Note] Plugin 'FEDERATED' is disabled. 141104 18:36:28 InnoDB: The InnoDB memory heap is disabled 141104 18:36:28 InnoDB: Mutexes and rw_locks use GCC atomic builtins 141104 18:36:28 InnoDB: Compressed tables use zlib 1.2.3 141104 18:36:28 InnoDB: Initializing buffer pool, size = 128.0M 141104 18:36:28 InnoDB: Completed initialization of buffer pool 141104 18:36:28 InnoDB: highest supported file format is Barracuda. 141104 18:36:32 InnoDB: Waiting for the background threads to start 141104 18:36:33 InnoDB: 5.5.38 started; log sequence number 1711074 141104 18:36:33 [Note] Server hostname (bind-address): '0.0.0.0'; port: 8889 141104 18:36:33 [Note] - '0.0.0.0' resolves to '0.0.0.0'; 141104 18:36:33 [Note] Server socket created on IP: '0.0.0.0'. 141104 18:36:35 [Note] Event Scheduler: Loaded 0 events 141104 18:36:35 [Note] /Applications/MAMP/Library/bin/mysqld: ready for connections. Version: '5.5.38' socket: '/Applications/MAMP/tmp/mysql/mysql.sock' port: 8889 Source distribution Hello phpFreaks! I want to ask you if there are some ways to make your php program works with serial number (that you give in people that bought it). So the one that buy it can't copy and give it to his friend..Or something... Is there any way to make this with php ? Thanks alot! I need to execute a program in the command prompt in windows using php, which php functions would be best to do this? and would i need to set any type of permissions to be able to use them? HI,
I am a beginner at programing and I have to do this project where it is asking me to valid ISBN 10 and 13 using MySQL database to store the information. I checked my php code to validate ISBN 10 and 13 and it works, but when I try to store the data to MySQL it is not working. What I mean is that when I click ShowISBN link it doesn't show this information:
ISBN Number
ISBN Type
Date Entered using timestamp
Valid or Invalid
This is the codes I have for input page of ISBN page:
<?php //this is the isset function which allows us to submit back //to the same form. If there isn't anything in the ISBN, it will //show the bottom part of the form if(isset($_POST["ISBN"])|| empty($_POST['isbn_type']) || empty($_POST['Valid_Invalid'])) { $ISBN = $_POST["ISBN"];; $IsbnType = $_POST["isbn_type"];; $VaorIn = $_POST["Valid_Invalid"];; $ISBN_Arr = str_split($ISBN); $not10 =0; $notNum=0; $notX=0; //entering error checking for the code //check for 10 first, if clear do additional checking if(strlen($ISBN) == 10) {//start further error checking //check to make sure first 9 are numeric for($i=0;$i<=8;$i++) { if(!is_numeric($ISBN_Arr[$i])) $notNum = 1; }//end for loop check //check to see if there is a X or a x if($ISBN_Arr[9]=='x' || $ISBN_Arr[9]=='X') { $ISBN_Arr[9] = 10; } //if not an x, is it at least numeric? else if (!is_numeric($ISBN_Arr[9]) ) { $notX=1; } }//end additional error checking else { $not10=1; }//end not 10 check //start of error messages if prereqs are not met if($notNum ==1 || $notX ==1 || $not10) { Print "<h2>Input error</h2><br/>"; Print "Here is the error(s) discovered:<br/>"; if($notNum ==1) print"Your ISBN contains non-numeric data.<br/>"; if($notX ==1) print"The last digit is not a number or a X.<br/>"; if($not10 ==1) print"ISBN 10 number should contain 10 characters.<br/>"; include"ISBN_not_val_include.html"; } //end error checking else{ $chk_sum_num=10; $chk_sum =0; for($i=0;$i<=9;$i++) { $chk_sum +=$ISBN_Arr[$i] *$chk_sum_num; //print"$ISBN_Arr[$i] | $chk_sum_num<br/>"; $chk_sum_num--; }//end for loop $is_valid_ISBN= $chk_sum%11; //print"chk_sum: $chk_sum </br> is_valid_ISBN: $is_valid_ISBN</br>"; if($is_valid_ISBN==0) { print"<h3>VALID</h3><br/>"; print"$ISBN is a VALID 10 digit ISBN number.<br/>"; include"ISBN_val_include.html"; } else{ print"<h3>INVALID</h3><br/>"; print"$ISBN is an INVALID 10 number ISBN.<br/>"; include"ISBN_not_val_include.html"; }//end is_valid if }//end }//end is set if else{ include"ISBN_val_include.html"; }//end isset else ?> </form> <p><a href="_ShowISBN10and13DBProject.php">Show ISBN </a></p> </body> </html>This is the second part of the code that incorporates php and MySQL: <?php if (empty($_POST['ISBN'])|| empty($_POST['isbn_type']) || empty($_POST['Valid_Invalid'])) echo "<p>You must enter a Valid ISBN 10 to Continue! Please Click your browser's Back Button to return to the input page of ISBN 10 with Database.</p>\n"; else { $DBConnect = @mysql_connect("xxx.xxx.xx.xxx", "xxxxxxxx", "xxxxxxxx"); if($DBConnect === false) echo"<p>Unable to conenct to the database server.</p>" . "<p>Error code " . mysql_errno() . ": " . mysql_error() . "</p>"; else{ $DBName = "xxxxxxxx"; if (!@mysql_select_db($DBName, $DBConnect)) { $SQLstring = "CREATE DATABASE $DBName"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if ($QueryResult === FALSE) echo "<p>Unable to execute the query.</p>" . "<p>Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "</p>"; else echo "<p>You are the first visitor!</p>"; } mysql_select_db($DBName, $DBConnect); $TableName = "isbn"; $SQLstring = "SHOW TABLES LIKE '$TableName'"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if ($QueryResult === FALSE) echo "<p>Unable to create the table.</p>" . "<p>Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "</p>"; $ISBNum = stripslashes($_POST['ISBN']); $ISBNType = stripslashes($_POST['isbn_type']); $VaORIn = stripslashes($_POST['Valid_Invalid']); $SQLstring = "INSERT INTO $TableName VALUES(NULL, '$ISBNum', '$ISBNType', '$VaORIn')"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if($QueryResult === false) echo"<p>Unable to execute the query.</p>" . "<p>Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "</p>"; else echo"<h1>Thank you for trying our ISBN 10 program!</h1>"; mysql_close($DBConnect); } } ?><!--End PHP Script-->This is the page where it is not working! <?php $DBConnect = @mysql_connect("xxx.xxx.xx.xxx", "xxxxxxx", "xxxxx"); if($DBConnect === false) echo"<p>Unable to conenct to the database server.</p>" . "<p>Error code " . mysql_errno() . ": " . mysql_error() . "</p>"; else{ $DBName = "xxxxxx"; if (!@mysql_select_db($DBName, $DBConnect)) echo"<p>There are no entries in the guest book!</p>"; else { $TableName = "isbn"; $SQLstring = "SELECT * FROM $TableName"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if (mysql_num_rows($QueryResult) == 0) echo"<p>There are no entries in the ISBN 10 Database!</p>"; else{ echo"<p>The following ISBN have been recorded:</p>"; echo"<table width='100%' border='1'>"; echo"<tr><th>ISBN Number</th><th>ISBN Type</th><th> Date Entred</th><th> Valid OR Invalid</th></tr>"; while (($Row = mysql_fetch_assoc($QueryResult)) !==FALSE) { echo "<tr><td>{$Row['ISBN']}</td>"; echo "<tr><td>{$Row['isbn_type']}</td>"; echo "<tr><td>{$Row['TIMESTAMP']}</td>"; echo "<td>{$Row['Valid_Invalid']}</td></tr>"; } } mysql_free_result($QueryResult); } mysql_close($DBConnect); }When I click show ISBN nothing happens and I am not shore why! This is how I have my table setup in MySQL Manually by clicking table and create table: Columns: count int(11) Al PK ISBN varchar(45) isbn_type varchar(45) TIMESTMP datetime PK Valid_Invalid varchar(45) Can someone please tell me why when I click Show ISBN in the input page the first code pasted I get nothing! How do I fix the issue because my validation works, but it's not storing it or showing up when click Show ISBN! Any help will be appreciate it! I'd like to put a password requirement in this program & an expiration date (database record)so that at 11 months I output an alert and at the end of one year it shuts down. ? The below code works for the password but I can't find how to link to my main page? PHP Code: <?php mysql_connect(localhost,root,""); mysql_select_db(entrydb) or die( "Unable to select database"); if(!empty($_POST["submit"])) { $password = $_POST['password']; $expdate = $_POST['expdate']; $query="SELECT password, expdate FROM entrydata Where password='$password'"; $result=mysql_query($query); if(mysql_num_rows($result)) { echo "<form action='#' method='post'>"; echo "</form>"; } else{echo "Access denied<br />";} } ?> <form method="post" action="#"><br /> <input type="text" name="password"/><p> <input type="submit" name="submit" value="enter password"/> </form> I have a situation where I need to sort files on a screen based on the date that is embedded into the file name. The problem is that I am sorting based off the file name, and when I get my output the LEGACY file always comes out on top of the sort because it starts with a 0 meanwhile the rest have dates appended the the filename so I don't have a problem sorting those. Please help me if you can. <? //Special case for extra files IF($Recordmyrow['App'] == "(Printable)") { $display = false; $column3 = "Printable VER"; IF($securityvalue == "P") { if(substr($path, 0, 5) == "file:") { $filename = substr($path, 5); if(file_exists($filename)) { $basename = substr($filename, 0, strrpos($filename, '.')); $ext = ".pdf"; $allfiles = glob("{$basename}*.pdf"); rsort($allfiles, SORT_NUMERIC); foreach($allfiles as $file) { if($ext == ".pdf") { $column4 = "<a href=\"pdf.php?src={$file}\">VIEW</a><br />\n"; $codate = substr($file, 70, 8); $co = substr($file, 59, 1); if ($codate != "pdf") { $column3 = "Printable File - ".$codate; } elseif ($codate == "pdf") { $column3 = "Printable File - LEGACY"; } IF($lastGroup != $Recordmyrow['Grouping']) { $lastGroup = $Recordmyrow['Grouping']; ?> <TR> <TD colspan="4" align="center" bgcolor="#418765"><B><FONT color="white"><? echo $Recordmyrow['Grouping'] ?></FONT></B></TD> </TR> <? } ?> <TR> <TD class="display" align="center" bgcolor="<?=changeColor($rowcount)?>"><B><? echo $column1 ?></B></TD> <TD class="display" bgcolor="<?=changeColor($rowcount)?>"><B><? echo $column2 ?></B></TD> <TD class="display" bgcolor="<?=changeColor($rowcount)?>"><B><? echo $column3 ?></B></TD> <TD class="display" bgcolor="<?=changeColor($rowcount)?>" align="center"><B><? echo $column4 ?></B></TD> </TR> <? $rowcount++; } } } else { $column4 = "Not Available"; ?> <TR> <TD class="display" align="center" bgcolor="<?=changeColor($rowcount)?>"><B><? echo $column1 ?></B></TD> <TD class="display" bgcolor="<?=changeColor($rowcount)?>"><B><? echo $column2 ?></B></TD> <TD class="display" bgcolor="<?=changeColor($rowcount)?>"><B><? echo $column3 ?></B></TD> <TD class="display" bgcolor="<?=changeColor($rowcount)?>" align="center"><B><? echo $column4 ?></B></TD> </TR> <? $rowcount++; } } } } Hello. I have a multi dimensional array that needs to be sorted. Array top25 [index][product id][number_of_purchases]. The index will contain a unique number for each product id. First product will be 1, second product will be 2, etc. The product id will be a id number like 34324ac9a89. The number of purchases will be how many times the item has been purchased. - End result: I want to print the 25 most purchased products in this format. product id - number of purchases a39acz - 503 a8cz9c - 480 zc8ac - 392 How do I do this? Thanks Part of my code: Code: [Select] <?php $arr = array ("Christina", "Daniel", "Andreea); reset($arr); foreach ($arr as $username) { //more code here ... foreach ($stats as $result) { echo $username."'s points - ".$result."<br />"; } } ?> And gives this: Code: [Select] Christina's points - 14 Daniel's points - 45 Andreea's points 23 My question is: can you sort the the $result so it will show Code: [Select] Daniel's points - 45 Andreea's points 23 Christina's points - 14 Thank you Just a further question from a earlier post that was complete if i do a search and i want to order them from a drop box the if statement would it just look like Quote "select * from Table order by '".$_POST['order']."'" Or would this not work ? Thanx i need to sort my database results by the day they were added to the database. There is a column with the timestamp of when they were inserted but how do i group them by the day they were inserted so i can display them as such: Mon 14th: 5 records Tues 15th: 11 records etc. |