laffin
Members-
Posts
1,200 -
Joined
-
Last visited
Everything posted by laffin
-
Grab data from multiple checkboxes and multiple dropdowns
laffin replied to tsm1248's topic in PHP Coding Help
You don't tie in your checkbox with its dropdown list if ($row2['priv']==prov){print '<option value="'.$row2['user'].'" name="prov['.$i++.']">'.$row2['user'].'</option>';} } change to: if ($row2['priv']==prov){print '<option value="'.$row2['user'].'" name="prov['.$row['id'].']">'.$row2['user'].'</option>';} } checkbox returns a value only when checked listbox returns 1 item which is selected so the key for the listbox can be the value from the checkbox, so know you know which checkbox belongs to which list item this creates a mult-dimensional array in your code check yer checkboxes $delete[]=array(); if(isset($_POST['delete'])) { foreach($_POST['delete'] as $ticket) $delete[]=$_POST['prov'][$ticket]; } echo count($delete) . " tickets to remove <br />"; for($i=0;$i<count($delete);$i++) { $n=$i+1; echo " #{$n} - {$delete[$i]} <br />"; } -
cant use ' in a " string for the keyname unless variable name is encapsulated with curly braces. and u missed the removal of the concatenation operator. all these would be valid query = mysqli_query($connexion, "SELECT name FROM myusers WHERE myidnum = '".$_SESSION['myid']."'"); query = mysqli_query($connexion, "SELECT name FROM myusers WHERE myidnum = '$_SESSION[myid]'"); query = mysqli_query($connexion, "SELECT name FROM myusers WHERE myidnum = '{$_SESSION['myid']}'");
-
[quote author=desjardins2010 link=topic=318075.msg1499736#msg1499736 date=1292200090] $recent = mysql_query("SELECT * FROM phpbb_posts ORDER BY post_time DESC LIMIT 5"); [code=php:0] [/quote] You only really need 1 query. [code=php:0]$recent = mysql_query( "SELECT phpbb_posts.id AS post_id, phpbb_posts.topic_id AS topic_id, phpbb_posts.forum_id AS forum_id, phpbb_posts.poster_id AS poster_id, phpbb_topics.topic_title AS title, phpbb_users.username AS username FROM phpbb_posts, phpbb_topics ON phpbb_posts.topic_id=phpbb_topics.id, users ON phpbb_posts.poster_id=users.id ORDER BY post_time DESC LIMIT 5");
-
Are there any free live editors for PHP and other files?
laffin replied to OM2's topic in PHP Coding Help
The only difference between having ftp an enabled ftp editor, is that u dont have to switch back and forth between your ftp client and your editor. as long as you remember the EOL are different on Windows/Dos/Linux/MAC. so make shure to set your ftp client and your editor with the appropriate EOL terminators. Otherwise it can create a real mess of your files. -
Are there any free live editors for PHP and other files?
laffin replied to OM2's topic in PHP Coding Help
There isnt any editor that can edit LIVE as u say, they download the content, u edit it, and it uploads it. Take a look at Notepad++ Has FTP, supports multiple languages, and all around easy editor to use. Myself, been using UltraEdit for years. has plenty of features. -
<?php $teams=135; $participants=$teams; $cur_round=1; $total_matches=$offset=0; while($participants>1) { $matches=floor($participants/2); $total_matches+=$matches; echo "Round #{$cur_round}: {$matches} matches {$offset} offset <br />". PHP_EOL; $offset+=ceil($participants/2); $cur_round++; $participants-=$matches; } echo "Winner after {$total_matches} matches. <br />". PHP_EOL; See no hard coding required if u have the proper math involved.
-
Yes, there are a number of cron for windows, i think wincron is one. and there are other alternatives besides cron, if yer php supports system/pcntl.
-
Uhm, thats what dynamic is. A system by which changes according to the variables. Hardcoding things, is static, like html pages, cant change a thing unless u edit the html script dynamic pages, give it a few variables, and it gives data out according to those variables.
-
The problem is your system is hardcoded, as u said your extending it to support 128 teams. a system like i describe is dynamic, the tables/rounds are all generated at run time, not design time.
-
Pretty familiar with tourneys, but there is no real sense to your logic. you don't really define teams, nor does yer system promote the winner of the round nor do you express which rounds a team is participating in when you define those variables, its much easier to imagine the system, which is nothing more than the elimination of a team, and move to the next round, until you have 1 winner. Very Simple Tourney system to get you started <?php $teams=array('Alpha','Beta','Gamma','Delta','Epsilon','Zeta','Eta'); $round=0; $participants=$teams; while(count($participants)>1) { $round++; // Increment our round Echo 'Round '. $round. PHP_EOL; $tables=array(); // Clear our tables $index=0; while(count($tables) < floor(count($participants)/2)) // want an even amount of tables $tables[]=array($participants[$index++],$participants[$index++]); if($index<count($participants))// extra team, add to tables, but no opposing team $tables[]=array($participants[$index++],NULL); $participants=array(); // clear out next round participants foreach($tables as $idx=>$table) { $tbl=$idx+1; echo " Table #{$tbl}: "; if($table[1]===NULL) // extra team advances to next level automatically { echo "{$table[0]} Holdover"; $winner=0; } else { echo "{$table[0]} vs. {$table[1]}"; $winner=rand(0,1); // Generate a winner } echo " - Winner {$table[$winner]}". PHP_EOL; $participants[]=$table[$winner]; // Add WInnerto next round } }
-
Simple Social Network System: MySQL Query help needed
laffin replied to Asator's topic in PHP Coding Help
$fetchFriends = mysql_query("SELECT DISTINCT * FROM usersTable JOIN friendshipTable ON friendshipTable.userID_1=usersTable.userID OR friendshipTable.userID_2=usersTable.userID WHERE friendshipTable.userID_1='$id' OR friendshipTable.userID_2='$id' "); try that -
reason the code was pseudo code The code does not work, but it helps ppl see some how code would intereact with each other. So I'm not shure why you posted here if yer reply has nothing to do with the topic. You are not helping, nor are u posting a query. Troll forums are on other websites not here. also the reason i posted that javascritpt has jquery. If yer client app has a means to communicate with a web server, than its just a matter of designing the protocol. thats all any api does.
-
elseif(!is_numeric($numCheck)){return false;} a paren isnt a number
-
if yer using java/javascript/flash these are run clientside (mostly) php is serverside. so your app must communicate with the webserver, javascript has jquery which is popular and easy as well as ajax. the serverside, php script, just returns information tat the app needs usually with a GET request. these scripts usually post information as xml or plain text. pseudo app code: function get_oppenent_respnse() { return = file_get_contents("http://my.server.com/playerresponse.php?myid=x&table=y"); } while server side u would have <?php header('Content-type: text/plain'); $id=isset($_GET['myid'])?intval($_GET['myid']):FALSE; $table=isset($_GET['table'])?intval($_GET['table']):FALSE; if($id && $table) { $row=sql_query("SELECT * responses WHERE table=$table and to=$myid"); echo "$row[from]:$row[response]"; } its just designing the interation between client and server.
-
i think (off the top of my head) preg_match('/^\(?\d{3}\)?[\.\- ]?\d{3}[\.\- ]\d{4}$/',$phone): should capture: (xxx) xxx-xxxx (xxx)-xxx-xxxx xxx.xxx.xxxx xxxxxxxxxx or any combination thereof
-
I much prefer $addr = 'http://google.com'; $fp = file_get_contents($addr); header('Content-type: text/plain'); echo $fp;
-
nope that looks right $field[0] = "Student Name"; $field[1] = "fail"; $field_ser = serialize($field); print_r($field_ser); $field_unser = unserialize($field_ser); print_r($field_unser);
-
no the code i had is fine remember it's an array so $_POST['order'] will hold array ( 1,5,7,9 ) or if one order array(5) the elements are the order id so u can update of the db either by inserts if using a seperate table or update if its the field is attached to an already existing table foreach($orders as $orderid) mysql_exec("INSERT INTO orders_sent (id,senton) VALUES($orderid,NOW())"); or $order=implode(',',$order); mysql_exec("UPDATE ORDERS senton=NOW() WHERE id IN ($order)"); $order is an array, so u access each element as you would a normal array.
-
Problem #1: echo '<tr><form action="order_sent.php" method="post"><td align="left"> U have this in the while loop, yet the submit button is outside of the while loop. Fix: I suspect that this is one form, so this line should be above the while loop. Problem #2 <input type="checkbox" name="order[]" value=''></tr>' You show the name and id of the particular row, however when it comes to the forum input, u don't specify to which id this checkbox belongs to. U have to let php know somehow. Checkboxes are funny thing, if left uncheck they don't return a name/value pair for the checkbox, when checked, the name/value pair is sent Fix: <input type="checkbox" name="order[]" value='{$row['id']}'></tr>' So when u do check a number of orders, php will have $_POST['order'] as an array with selected id's. but always check if it's set before U add it to a variable if(isset($_POST['order']) $order=$_POST['order] else $order=array();
-
I've done something like that a long long long time ago, it was to administer the installation settings and maintain them. I took the path that CrayonViolent is suggesting, by storing the variables as a php script to be included, the other option is to store them as serialized data, but i wouldn't recommend saving the serialized data as just a file, a php file ok <?php $sample=array( 'name'=>'John Doe', 'password'=>'JaneDoe' ); $data='<?php $config=unserialize(\''. serialize($sample) .'\'); ?>'; file_put_contents('config.php',$data); ?>
-
Building your own web scraper, i would consider using a toolbox/library that handles html/xml tags. as they can get pretty convoluted. Building your own from scratch, will be specific for certain pages not intended for generalized use. As stated xml/html can get pretty convoluted so will throw off your patterns and such. <?php $data=<<<EOF <?xml version="1.0" encoding="utf-8"?> <Result Code="OK" ErrorMessage="" FullError=""> <GlobalVars IndexBuildDate="17/04/2010 16:43:46" MostRecentBackLinkDate="2010-03-25"/> <DataTables Count="1"> <DataTable Name="Results" RowsCount="1" Headers="ItemNum|Item|ResultCode|Status|ExtBackLinks|RefDomains|AnalysisResUnitsCost|ACRank|ItemType|IndexedURLs|GetTopBackLinksAnalysisResUnitsCost|RefIPs|RefSubNets|RefDomainsEDU|ExtBackLinksEDU|RefDomainsGOV|ExtBackLinksGOV|RefDomainsEDU_Exact|ExtBackLinksEDU_Exact|RefDomainsGOV_Exact|ExtBackLinksGOV_Exact"> <Row>0|majesticseo.com|OK|Found|28381|1229|28381|-1|1|4774|28381|1074|954|1|5|0|0|0|0|0|0</Row> <Row>1|majesticseo.com|OK|Found|28381|1229|28381|-1|1|4774|28381|1074|954|1|5|0|0|0|0|0|0</Row> </DataTable> </DataTables> </Result> EOF; $data=preg_match_all('@<Row>(.*)?</Row>@',$data,$matches); $data=array(); foreach($matches[1] as $match) $data[]=explode('|',$match); print_r($data);
-
need help with redirect to secured page and back if not a user
laffin replied to webguync's topic in PHP Coding Help
Yes, but you arent sending any info to the next page, all $_POST/$_GET data is lost. Reason, I put Processing of variables. -
need help with redirect to secured page and back if not a user
laffin replied to webguync's topic in PHP Coding Help
Some thing u must understand 1) Sessions don't work without a sessiion_start() before any output is sent out this includes header() 2) header() doesnt work if output has been sent out (with exception of rule #1) All in one forms work great, however they require a lot of planning. so start with your form: <html> <head> <body> <form name=form1 method="post" action="?"> <input type="text" name="textbox"> <input type="submit" name="submit"> </form> </body> </head> </html> the action='?' just redirects to itself now add your validation code at top <?php if(isset($_POST['name'])) { $name=trim($_POST['name']); if(strlen($name)) { // do processing of the variables (no output); // like inserting into db etc header('Location: nextpage.php"); // or if u need to send the nextpage somthing, from the processing procedure // header('Location: nextpage.php?name=".htmlspecialchars($name)); die(); // we are done } // we get here when we did have a name but it was empty echo "<h3>Bad Form entries, try again</h3>". PHP_EOL; } ?> [code] Very simple, when u think about it logically. -
u didnt assign a key: href="view_images.php?= should look more like: href="view_images.php?id= this way when using $_GET, u know which key/value pair to pull
-
yer not using curly braces { } for your blocks of code. parens ( ) usually define an expression