premiso
Members-
Posts
6,951 -
Joined
-
Last visited
-
Days Won
2
Everything posted by premiso
-
ummm.... http://www.google.com/search?hl=en&q=mod_rewrite+tutorial&btnG=Google+Search&aq=f&oq=
-
displaying number of comments for a custom blog
premiso replied to PhraiL's topic in PHP Coding Help
SELECT count(commentid) as commentCount FROM table_name GROUP BY parentid; Should do it. -
Making a login page with "PHP and MYSQL for Dummies"
premiso replied to Akskater1000's topic in PHP Coding Help
You have to have the <?php ?> tags for it to highlight. It also has to have the right extension. So a new file needs to saved as a .php for proper highlighting. -
displaying number of comments for a custom blog
premiso replied to PhraiL's topic in PHP Coding Help
Something like this: SELECT count(commentid) as commentCount FROM table_name WHERE parentid = 1; Something like that would do it. -
Making a login page with "PHP and MYSQL for Dummies"
premiso replied to Akskater1000's topic in PHP Coding Help
Download notepad++ if you plan on actually coding. It highlights syntax etc for PHP and what not. Great small and free program imo. When you find 105 you should be able to figure out the error, if not post it and we will help. -
Output to browser during execution (ob_flush?)
premiso replied to opalelement's topic in PHP Coding Help
<?php $from = $_POST['from']; $to_whole = $_POST['to']; $subject = $_POST['subject']; $message = $_POST['message']; $to = explode(",", $to_whole); for($i = 0; $i < count($to); $i++) { mail($to[$i], $subject, $message, "From: $from"); echo "Mail Sent to " . $to[$i] . "<br />"; ob_flush(); flush(); } ?> Should do it. -
It keeps them in a GET/POST array. <?php echo $_GET['test']; ?> Would output "testing".
-
<?php } ///EVERYTHING BELOW THIS IS NOT SHOWING/// echo " --Page $pagenum of $last-- <p>"; if ($pagenum == 1) {} else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> "; } echo " ---- "; if ($pagenum == $last) {} else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> "; } ?> </table> <?php } ?> Try that.
-
"SELECT * FROM topsites LIMIT $max" You need the LIMIT keyword in there before $max.
-
Are you sure you had data in your database? And that you have a valid SQL connection? <?php $sql = "SELECT id, zip FROM zipcodes ORDER BY id"; $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_row($result)) { $aUsers[$row['id']] = $row['zip']; } print_r($aUsers); ?> That should work as long as you have a valid connection and data in the database.
-
<?php define("SERVER_PATH", $_SERVER['DOCUMENT_ROOT'] . "/"); define("SERVER_URL", "http://" . $_SERVER['HTTP_HOST'] . "/"); include(SERVER_PATH . "includes/header.html"); ?> header.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="stylesheet" href="<?php echo SERVER_URL; ?>includes/style.css" type="text/css" media="screen" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Page Title</title> </head> <body> <div id="header"> <h1>Your website</h1> <h2>catchy slogan</h2> </div> <div id="navigation"> <ul> <li><a href="index.php">Home Page</a></li> <li><a href="calculator.php">Calculator</a></li> <li><a href="dateform.php">Date Form</a></li> <li><a href="#">Link Four</a></li> <li><a href="#">Link Five</a></li> </ul> </div> <div id="content"><!-- Start of the page-specific content. --> <!-- Script 3.2 - header.html --> Should get you the right results, note change header.html to .php so it can parse php.
-
<?php $sql = "SELECT id, zip FROM zipcodes ORDER BY id"; $result = mysql_query($sql); while(list($id, $zip) = mysql_fetch_row($result)) { $aUsers[$id] = $zip; } print_r($aUsers); ?> Maybe that is what you are looking for.
-
I think you have to do a multiple query with a recursive function. I do not think it is possible with 1 query. Or just do one query and use PHP to traverse the array returned and order it like you want. Here is an example of what I used to accomplish this: <?php /* * My attempt at a category script. */ /* create table categories ( catid INT(11) NOT NULL auto_increment, parentid INT(11) NOT NULL default '0', catname varchar(50) NOT NULL, catseoname varchar(50) NOT NULL, disporder INT(3) NOT NULL default '0', primary key(catid) ); */ mysql_connect("localhost", "root", ""); mysql_select_db("cat"); /* my test data insert into categories (`parentid`, `catname`, `catseoname`, `disporder`) VALUES ('0', 'Test1', 'test1', '0'); insert into categories (`parentid`, `catname`, `catseoname`, `disporder`) VALUES ('1', 'Test1-1', 'test1-1', '0'); insert into categories (`parentid`, `catname`, `catseoname`, `disporder`) VALUES ('1', 'Test1-2', 'test1-2', '1'); insert into categories (`parentid`, `catname`, `catseoname`, `disporder`) VALUES ('5', 'Test2-1', 'test2-1', '0'); insert into categories (`parentid`, `catname`, `catseoname`, `disporder`) VALUES ('0', 'Test2', 'test2', '1'); insert into categories (`parentid`, `catname`, `catseoname`, `disporder`) VALUES ('5', 'Test2-3', 'test2-2', '2'); insert into categories (`parentid`, `catname`, `catseoname`, `disporder`) VALUES ('6', 'Test2-2-2', 'test2-2-2', '1'); insert into categories (`parentid`, `catname`, `catseoname`, `disporder`) VALUES ('6', 'Test2-2-1', 'test2-2-1', '0'); insert into categories (`parentid`, `catname`, `catseoname`, `disporder`) VALUES ('5', 'Test2-3', 'test2-2', '2'); insert into categories (`parentid`, `catname`, `catseoname`, `disporder`) VALUES ('7', 'Test2-2-2-1', 'test2-2-2-1', '1'); insert into categories (`parentid`, `catname`, `catseoname`, `disporder`) VALUES ('7', 'Test2-2-2-2', 'test2-2-2-2', '0'); insert into categories (`parentid`, `catname`, `catseoname`, `disporder`) VALUES ('7', 'Test2-2-2-3', 'test2-2-2-3', '0'); insert into categories (`parentid`, `catname`, `catseoname`, `disporder`) VALUES ('3', 'Test1-2-1', 'test1-2-1', '1'); insert into categories (`parentid`, `catname`, `catseoname`, `disporder`) VALUES ('3', 'Test1-2-2', 'test1-2-2', '0'); */ function retrieveCategoryList($parentid=false) { if ($parentid === false) { $query = mysql_query("SELECT catid, parentid, catname, catseoname, disporder FROM categories WHERE parentid = 0 ORDER BY disporder, catname"); }else { $query = mysql_query("SELECT catid, parentid, catname, catseoname, disporder FROM categories WHERE parentid = " . $parentid . " ORDER BY disporder, catname"); } $numRows = mysql_num_rows($query); $catArray = "none"; if ($numRows > 0) { $catArray=array(); while ($row = mysql_fetch_assoc($query)) { $catArray[$row['catname']]['id'] = $row['catid']; $catArray[$row['catname']]['parentid'] = $row['parentid']; $catArray[$row['catname']]['catseoname'] = $row['catseoname']; $catArray[$row['catname']]['catname'] = $row['catname']; $catArray[$row['catname']]['disporder'] = $row['disporder']; $catArray[$row['catname']]['subcats'] = retrieveCategoryList($row['catid']); } } return $catArray; } function displayCats($cat=false, $charDisp=0) { if (!$cat) { if ($charDisp != 0) { $cats = retrieveCategoryList($charDisp); }else { $cats = retrieveCategoryList(); } foreach ($cats as $cat) { displayCats($cat); } }else { echo str_repeat("_", $charDisp) . $cat['catname'] . "<br />"; if ($cat['subcats'] != "none") { foreach ($cat['subcats'] as $value) { displayCats($value, $charDisp+1); } } } } displayCats(false, 6); echo "<pre>"; // Lets just pull out a set of categories. print_r(retrieveCategoryList()); ?>
-
<?php $data = file('variables.php'); $data[1] = '$name = '.$_POST['info'] ." \r\n"; // entry 1 is the 2nd line file_put_contents('variables.php',$data); ?>
-
foreach ($_POST as $key => $val) { if (stistr($key, "fare") !== false) { $sets[] = $key . " = '" . $val . "' "; } } $update = implode(", ", $sets); $query = "UPDATE restHotel SET " . $sets . " WHERE id = '$id'"; $result = mysql_query($query) or die ("Error in Updating the query: $query. ".mysql_error()); Should do the trick.
-
<?php $data = file('variables.php'); $data[1] = "$name = ".$_POST['info'] ." \r\n"; // entry 1 is the 2nd line file_put_contents('variables.php',$data); ?> That should work.
-
His code works, but seriously. If you are doing AJAX, look into jQuery it takes alot of the guessing work out of it and is secure/consistent. And it makes it really easy to use.
-
strstr or stristr Would be the way. <?php $string = "hello"; if (stristr($string, "e") !== false) { echo $string . " has e in it!"; } ?>
-
The best way to learn is trial and error. See what document_root spits out, and figure out how to put it into your code. I could just write it for you, but then you do not learn. Relative path means you use ../ etc so it is "relative" to your current position. Absolute path means you link directly to each file IE: /home/www/user/includes/file.php The absolute is preferred because then you can put your script in any folder and it should work. Trial and error is one of the best ways to learn, although frustrating, when you figure it out you tend to know more about what to do and what not and it sticks with you.
-
Look into jQuery, doubt anyone is going to write it for you. Also read up on Javascript, but you should find plenty of examples of AJAX with jQuery. Time to learn something new!
-
Smarty Template System is probably the best/most robust out there. That is my suggestion.
-
Post the code you want to be refreshed...the simplest way that comes to mind is using meta refresh or javascrit, so once the page is loaded it will refresh every 10 seconds. That would be my advice, echo out a meta tag or javascript to do this.