laffin
Members-
Posts
1,200 -
Joined
-
Last visited
Everything posted by laffin
-
<?php header('Content-Type: text/plain'); echo basename($_SERVER['PHP_SELF']); ?>
-
Well than we would need a different query to grab the field names, and use them instead of a numeric entry when calling mysql. than post these in a upper loop $rows=array(); while($info=mysql_fetch_array($result,MYSQL_ASSOC) // Changed from MYSQL_NUM to MYSQL_ASSOC, to provide headers { foreach($info as $key=>$val) { $rows[$key][]=$val; } } foreach($rows as $header=>$row) // Grab the header names from each column { echo "<tr><td>$header</td>'; foreach($row as $cell) { echo "<td>$cell</td>"; } echo '</tr>'; } was my mistake
-
You cant without a browser renderer. You probably want to use an external service such as http://thumbnailspro.com/
-
Ahhh glad when i have typos and mistakes, and user is able to fix em Gratz
-
remove the put functions and display it directly, once you got your output right add put. This looks like a continuation of the other post that retrieved values. for that I would opt for a reverse operation of the code posted there. $out=''; foreach($vars as $key=>$val) { $out.="$key=$val".PHP_EOL; } echo $out; if $out is what you want, then try using your ftp put function
-
Well than we would need a different query to grab the field names, and use them instead of a numeric entry when calling mysql. than post these in a upper loop $rows=array(); while($info=mysql_fetch_array($result,MYSQL_ASSOC) // Changed from MYSQL_NUM to MYSQL_ASSOC, to provide headers { foreach($info as $key=>$val) { $rows[$key][]=$val; } } echo '<tr>'; foreach($rows as $header=>$row) // Grab the header names from each column { echo "<td>$header</td>'; } echo '</tr>'; foreach($rows as $row) { echo '<tr>'; foreach($row as $cell) { echo "<td>$cell</td>"; } echo '</tr>'; }
-
oops change the =$id to ==$id
-
Did you even submit the form? if not use the form to get to this processing script or if it's a all in one form, check to see if this is a form submission if(!isset($_POST['submit'])) die('Form not submitted'); Wow, another post posted too late Nice going PFM
-
<?php $file_handle = fopen("myfile", "r"); // This is a standard text file, binary mode not needed $vars = array(); while (!feof($file_handle) ) { $line_of_text = fgets($file_handle); if(substr($line_of_text,0,1)=='#') continue; // This is to skip comment lines $parts = explode('=', $line_of_text); // Other lines in key=value pairs $vars[$parts[0]] = trim($parts[1]); // use trim to remove any unnecessary whitespace from key/values } fclose($file_handle); header('Content-Type: text/plain'); // we want to display a plain text file print_r($vars);
-
$rows=array(); while($info=mysql_fetch_array($result,MYSQL_NUM); { foreach($info as $key=>$val) { $rows[$key][]=$val; } } foreach($rows as $row) { echo '<tr>'; foreach($row as $cell) { echo "<td>$cell</td>"; } echo '</tr>'; }
-
can you post up a sample datafile?
-
echo count($test) .' Item(s) selected'; Hahaha, ya beat me to punch thorpe
-
PHP/mySQL query skip repeated results in column header
laffin replied to nullpoint81's topic in PHP Coding Help
I did this code to demonstrate for someone else <?php //header('Content-Type: text/plain'); $fnames='Norman,Bree,Savannah,Tatyana,Victor,Haley,Shea,Ivana,Frances,Hanae'; $snames='Walter,Floyd,Becker,Sears,Robertson,Barnes,Hurst,Barr,Gross,Cotton'; $zips='91752,10798,56244,68925,04025,48726,57696,20589,84348,19588'; $fnames=explode(',',$fnames); $snames=explode(',',$snames); $zips=explode(',',$zips); // Build sample DB $sdb=sqlite_open(':memory:'); $count=rand(21,35); sqlite_exec($sdb,'CREATE TABLE sample ( id INTEGER PRIMARY KEY, name VARCHAR( 40 ), surname VARCHAR( 40 ), zip NUMERIC );'); for($i=0;$i<$count;$i++) { $f=$fnames[rand(0,count($fnames)-1)]; $s=$snames[rand(0,count($snames)-1)]; $z=$zips[rand(0,count($zips)-1)]; sqlite_exec($sdb,"INSERT INTO sample (name,surname,zip) VALUES ('$f','$s',$z);"); } // Code of interest starts here // Get the max rows and set up our headers $res=sqlite_query($sdb,'SELECT zip,count(*) FROM sample GROUP BY zip ORDER BY zip;'); $max=0; $headers=array(); while($row=sqlite_fetch_array($res,SQLITE_NUM)) { $max=max($max,$row[1]); $headers[]=$row[0]; } // Retrieve the records, and place them in Column arrays $res=sqlite_query($sdb,'SELECT * FROM sample ORDER BY zip'); $crow=0; while($row=sqlite_fetch_array($res,SQLITE_ASSOC)) { if($row['zip']!=$headers[$crow]) { $crow++; } $Cols[$crow][]=$row; } // Format data $Rows=array(); for($i=0;$i<$max;$i++) { foreach($Cols as $col) { if(isset($col[$i])) $row="<a href=\"{$col[$i]['id']}\">{$col[$i]['name']} {$col[$i]['surname']}</a>"; else $row=' '; $Rows[$i][]=$row; } } // Display Table echo '<table><tr>'; foreach($headers as $header) { echo "<td>$header</td>"; } echo '</tr>'; foreach($Rows as $row) { echo '<tr>'; foreach($row as $cell) { echo "<td>$cell</td>"; } echo '</tr>'; } echo '</table>'; -
It's using Apache Mod Rewrite. Which takes one uri and formats it into another. A Quick google search for Apache Mod Rewerite tutorial pretty urls should give you a good examples but if you plan on making your own a good knowledge of regex is required
-
Nope, your a noob when it comes to a lot of things related to computer operations. .. denotes the directory above the current directory - these are relative paths - which yer script is using (look at the requires and includes) when they say to use an absolute path, they mean to use the full pathname, which should start at the root file structure /home/xxxx/www/include.php if you need help in getting the directory, try using this <?php echo getcwd(); ?> than update your cron job script with absolute paths
-
Because your insert is within the loop and there is no postid check, so you should have multiple inserts and you dont need '' around $id in the queries because they should be numeric if (isset($_POST["add"]) && $_POST['postid']=$id) { $name = $_POST["comname"]; $comment = $_POST["comment"]; $querys = "INSERT INTO comment (menu_title, post_id, date, name, comment) VALUES ('$dbtn', $id, CURDATE(), '$name', '$comment')"; mysql_query($querys) or die("Error, insert query failed: " . mysql_error()); echo '<br /><br />Thank You!'; } else { echo '<form method="post"><input type="postid" value="$id">';
-
Too bad there isnt a +1 to users, Love the response
-
shure it's easy if(@file_get_contents($image)) { } else { }
-
Need advice on how best to go through an array and match strings
laffin replied to OM2's topic in PHP Coding Help
I came up with this solution <?php $text=<<<EOF shipping_1: 0.00 first_name: Joe last_name: Bloggs email: [email protected] phone: 020 address1: 10 Road address2: city: London zip: EC1V 0HB collection-delivery: collection eshop_payment: cash item_name_1: item one quantity_1: 1 amount_1: 12.95 item_name_2: item number two quantity_2: 1 amount_2: 5.95 item_name_3: item num three quantity_3: 1 amount_3: 5.50 numberofproducts: 3 amount: 24.40 EOF; $template=<<<EOF shipping: {shipping:shipping_\d+} name: {first_name} {last_name} email: {email} phone: {phone} address: {address:address[12]}, {city} {zip} collection-delivery: {collection-delivery} eshop_payment: {eshop_payment} order: {items:(item_name|quantity|amount)_(\d+)} amount: {amount} EOF; header('Content-Type: text/plain'); function adddlm($pattern) { return "@^($pattern): (.*?)[\\r\\n]*\$@m"; } function process_address($match) { global $var; $var[]=$match[2]; } function end_address() { global $var; return implode(', ',$var); } function process_shipping($match) { global $var; $var[]=$match[2]; } function end_shipping() { global $var; return number_format(array_sum($var),2); } function process_items($match) { global $var; $var[$match[3]][$match[2]]=$match[4]; return $match[0]; } function do_item($item) { return "$item[quantity] X $item[item_name] $item[amount]"; } function end_items() { global $var; $var=array_map('do_item',$var); return implode(PHP_EOL,$var); } preg_match_all('@^([^:]+): (.*?)[\r\n]*$@m',$text,$matches,PREG_SET_ORDER); foreach($matches as $match) $vars[$match[1]]=$match[2]; preg_match_all('@{([^}]+)}@',$template,$matches); $output=$template; foreach($matches[1] as $tplfun) { if(strpos($tplfun,':')) { list($func,$patterns)=explode(':',$tplfun); $patterns=array_map('adddlm',explode(',',$patterns)); if(function_exists("process_$func")) { $var=NULL; preg_replace_callback($patterns,"process_$func",$text); $var=call_user_func("end_$func"); } else { $var='N/A'; } } else { $var=isset($vars[$tplfun])?$vars[$tplfun]:'N/A'; } $output=str_replace('{'.$tplfun.'}',$var,$output); } echo $output; ?> The only part I didnt implement was the multiple item sets line within the template, It's possible, just have to implement more code in the template structure. Takes two formats, simple replacement {var} and complex (multiple lines) -
I would personally store file information in a database, and give the file a unique name (also stored in the database). 1) Create a unique filename 2) if unique name exists, go to step 1 3) store file info, and unique filename in database. With a download script to give the proper filename
-
My bet is on the query itself mysql_query ("INSERT INTO users VALUES ('','$fullname','$username','$password','$date')"); try using the fieldnames mysql_query ("INSERT INTO users (fullname,username,password,addedon) VALUES ('$fullname','$username','$password','$date')"); of course your fieldnames will be different
-
<form method="post"> Search: <input type="input" name="search" maxlength="40" /> <input type="submit"> </form> <?php $book=$chapter=$verse=NULL; if(isset($_POST['search']) && !empty($_POST['search'])) { $search=urldecode($_POST['search']); preg_match('@(\w*)?\s*(?\d+)\d+))?@',$search,$match); $book=(!empty($match[1]))?$match[1]:NULL; $chapter=(!empty($match[2]))?$match[2]:NULL; $verse=(!empty($match[3]))?$match[3]:NULL; } $ok=TRUE; foreach(array('book','chapter','verse') as $term) { if(empty($$term)) { echo "Please enter $term<br />".PHP_EOL; $ok=FALSE; } } if(!$ok) die(); echo "Search in book ($book) $chapter:$verse"; ?> [/code]
-
Than why suggest html function, that would change all the <li> tags to <li> codes. I seen it as Text that is to be displayed as html, not as text that is to be displayed as html code.
-
addslashes is more appropriate for the content. if you notice all the html tags?
-
function addslashes