Daniel0
Staff Alumni-
Posts
11,885 -
Joined
-
Last visited
Everything posted by Daniel0
-
Nevermind this. I confused it with a select with multiple='multiple'... Besides, I found out that it doesn't return arrays anyways (unless you name it something like test[])... I know... I just gave you a shorter (and probably more efficient since your contains multiple loops) way of doing it. You can access it using $_POST... You can see in this little test script how the data will be like in $_POST: <form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post'> <select size='4' name='test'> <option value='1'>one</option> <option value='2'>two</option> <option value='3'>three</option> <option value='4'>four</option> </select><br /> <button type='submit'>Submit</button> </form> <?php print_r($_POST); ?>
-
I wonder how many customers they have for both 3D Mailbox and VisitorVille...
-
<select name="prop_area" size="1" class="boxes"> <?php $places = mysql_query("SELECT * FROM places ORDER BY name"); while($place = mysql_fetch_assoc($places)) { $selected = $place['id']==$area ? " selected='selected'" : null; echo "<option value='{$place['id']}'{$selected}>{$place['name']}</option>\n"; } ?> </select> Is better... I supposed that the fields were named id and name. I believe that if multiple selections are made, then it will be an array. Try to use print_r() and then die(). Then you can see what it does. Try with both a single value and multiple values selected, then you'll see.
-
if(count($array) > 0) { echo "is not empty"; } else { echo "is empty"; }
-
Maybe it's a stupid question, but how was the first assembly compiler then made? ???
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Checkboxes</title> </head> <body> <h1>Checkbox Demo</h1> <h2>Demonstrates checkboxes</h2> <form action='test.php' method='post'> <h3>What would you like with your order?</h3> <ul> <li><label><input type="checkbox" name="fries" value="1" /> Fries</label></li> <li><label><input type="checkbox" name="soda" value="1" /> Soda</label></li> <li><label><input type="checkbox" name="shake" value="1" /> Shake</label></li> <li><label><input type="checkbox" name="ketchup" value="1" /> Ketchup</label></li> </ul> <input type="submit" value="Order" /> </form> </body> </html> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Checkboxe Demo</title> </head> <body> <h2>Demonstrates reading checkboxes</h2> <?php $items = array( 'fries' => 1, 'soda' => .85, 'shake' => 1.3, 'ketchup' => .05, ); $list1 = null; $list2 = null; $total = 0; foreach($items as $name => $price) { $state = $_POST[$name]=='1' ? true : false; $list1 .= "{$name}: "; $list1 .= $state ? "yes" : "no"; $list1 .= "<br />"; if($state == true) { $list2 .= "You ordered '{$name}'<br />"; $total += $price; } } $total = number_format($total,2); echo <<<EOF {$list1} <hr /> {$list2}<br /> Your total price is: \${$total} EOF; ?> </body> </html>
-
Why are you declaring the methods protected? I'd do something like this: <?php final class Database { private static $instance = null; protected $username; protected $password; protected $host; protected $database; protected $connection; protected $last_result; private function __construct() { } public function __destruct() { } public static function getInstance() { if(is_null(self::$instance)) { self::$instance = new Database(); } return self::$instance; } public function connect($username, $password, $host, $database) { $this->username = $username; $this->password = $password; $this->host = $host; $this->database = $database; $this->connection = @mysql_connect($this->username, $this->password, $this->password); if(!$this->connection) throw new Exception("Failed connecting to database: ".mysql_error()); $select = mysql_select_db($this->database, $this->connection); if(!$select) throw new Exception("Failed selecting database: ".mysql_error()); } public function query($query) { $this->last_result = @mysql_query($query, $this->connection); return $this->last_result; } public function fetch_row($result=null) { $result = is_resource($result) ? $result : $this->last_result; return mysql_fetch_assoc($result); } public function get_num_rows($result=null) { $result = is_resource($result) ? $result : $this->last_result; return mysql_num_rows($result); } public function fetch_result($query) { $this->query($query); $result = $this->fetch_row(); $result['db_rows_returned'] = $this->get_num_rows(); return $result; } public function insert($table, $values=array()) { $started = 0; foreach($values as $field => $value) { if($started == 0) { $values_used = $field; $actual_values = "'{$value}'"; $started = 1; } else { $values_used .= ",{$field}"; $actual_values .= ",'{$value}'"; } } $result = $this->query("INSERT INTO {$table} ({$values_used}) VALUES({$actual_values})"); return $result; } public function update($table, $values=array(), $where) { $sets = array(); foreach($values as $field => $value) { $sets[] = "{$field}='{$value}'"; } $set = join(',',$sets); $where_sql = empty($where) ? null : " WHERE {$where}"; $result = $this->query("UPDATE {$tbl} SET {$set}{$where_sql}"); return $result; } public function errno() { return mysql_errno(); } public function error() { return mysql_error(); } } class DBException extends Exception { public function __construct($db) // do something a little more "advanced" here { die("Database error [{$db->errno()}]: {$db->error()}"); } } ?> Hmm... added a few extra methods :-\
-
What was your "last problem"? Also, you're using £total instead of $total. It might also be better to store the price in the script so people don't change it before submitting.
-
Hmm... I wrote the above code based on how I saw your page in FF, but apparently it didn't show the top navigation bar correctly (at least not like other browsers did). Fortunately it's just a matter of changing the background color for #nav-top in the CSS. style.css with fix for above-mentioned problem: * { margin: 0; padding: 0; } body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 95%; background: #F1F1F1; } #container { margin: 10px auto; width: 687px; } /* HEADER */ #header { height: 97px; background: url(http://www.warptweet.com/developzone/images/fpheader.jpg); } #header h1 { text-indent: -2000px; } /* TOP NAVIGATION */ #nav-top { padding: 3px; background: #6CAF2F; /* this line added */ } #nav-top li { display: inline; margin-left: 15px; } #nav-top li a:link, #nav-top li a:visited { color: black; font-size: 120%; text-decoration: none; } /* RIGHT NAVIGATION */ #right { background: #B2D95E; padding: 10px; min-height: 600px; } #right li { display: block; text-indent: 10px; } /* CONTENT */ #content { background-color: #ffffff; padding: 10px; width: 75%; min-height: 600px; float: left; } #content p { margin-bottom: 15px; } It should now look like this:
-
How doesn't it work? Telling us that it doesn't work doesn't help us particularly much. Post a screenshot of the page "not working". It [the code I posted] works for me in four browsers: FF, IE, Opera and Safari. Firefox 2.0.0.5 Opera 9.21 Internet Explorer 7 Safari 3.0.2
-
Have you run session_start() (both when setting and when trying to use it)?
-
Need some help on making subdomains on the go!
Daniel0 replied to ipwnzphp's topic in PHP Coding Help
It's not possible. The subdomain has to be created before it can be accessed. You could create the subdomain when the user registers though. I believe cPanel has some sort of API which you can use for this, but I think you need access to it's WHM to use it. -
[SOLVED] how to format the time_stamp date
Daniel0 replied to quickstopman's topic in PHP Coding Help
strtotime takes a formatted date and converts it to a UNIX timestamp. date takes a UNIX timestamp and formats it accordingly to the given format. See: http://php.net/strtotime and http://php.net/ -
index.html: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Home - Warptweet.com</title> <link rel='stylesheet' href='style.css' type='text/css' /> <!--[if IE]> <link rel='stylesheet' href='iefix.css' type='text/css' /> <![endif]--> </head> <body> <div id='container'> <div id='header'> <h1>Home - Warptweet.com</h1> </div> <div id='nav-top'> <ul> <li><a href='#'>Home</a></li> <li><a href='#'>Flash Portal</a></li> <li><a href='#'>Contact Us</a></li> <li><a href='#'>Submit Content</a></li> </ul> </div> <div id='content'> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vivamus quis eros. Maecenas ultrices commodo erat. Morbi lacus. Vestibulum nonummy fringilla sem. Pellentesque eu leo. Donec erat erat, hendrerit eu, condimentum a, porta id, mauris. Pellentesque a quam in mauris commodo aliquam. Proin eget nisi. Fusce ut nibh malesuada felis scelerisque pretium. Aenean semper consequat ligula. Nunc molestie, justo et lacinia ornare, dolor tortor facilisis arcu, sit amet euismod turpis tortor ac dolor. Nulla pulvinar leo ac sem. Sed vulputate neque.</p> <p>In a lacus. Nullam mollis libero quis ligula. Cras eget massa eget orci sodales faucibus. Vivamus pellentesque, erat eget ornare pulvinar, arcu lacus ultricies eros, in mollis urna erat vitae est. Fusce pretium dictum justo. Praesent ante est, consequat placerat, sodales id, cursus a, nisi. Praesent eget ante a ante bibendum congue. Proin et dolor eget dui lacinia sodales. Duis egestas laoreet dui. Praesent dictum dui at lorem. Nulla lacus metus, volutpat eget, pharetra eu, eleifend fringilla, mauris. Duis augue nisi, vestibulum quis, mollis quis, lacinia eget, eros. Nullam eget dolor. Proin nec ante a dui viverra hendrerit. Vivamus viverra massa nec lorem. Vivamus quam. Aliquam erat volutpat. Nam nec quam. Vivamus sapien neque, convallis eget, tincidunt eget, imperdiet ut, risus. In sapien tortor, aliquam in, consequat sit amet, tincidunt ac, arcu.</p> </div> <div id='right'> <ul> <li><a href='#'>Link 1</a></li> <li><a href='#'>Link 2</a></li> <li><a href='#'>Link 3</a></li> <li><a href='#'>Link 4</a></li> </ul> </div> </div> </body> </html> style.css: * { margin: 0; padding: 0; } body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 95%; background: #F1F1F1; } #container { margin: 10px auto; width: 687px; } /* HEADER */ #header { height: 97px; background: url(http://www.warptweet.com/developzone/images/fpheader.jpg); } #header h1 { text-indent: -2000px; } /* TOP NAVIGATION */ #nav-top { padding: 3px; } #nav-top li { display: inline; margin-left: 15px; } #nav-top li a:link, #nav-top li a:visited { color: black; font-size: 120%; text-decoration: none; } /* RIGHT NAVIGATION */ #right { background: #B2D95E; padding: 10px; min-height: 600px; } #right li { display: block; text-indent: 10px; } /* CONTENT */ #content { background-color: #ffffff; padding: 10px; width: 75%; min-height: 600px; float: left; } #content p { margin-bottom: 15px; } iefix.css: #right, #content { height: expression(this.scrollHeight > 600 ? "auto" : "600px"); } #right li { text-indent: 0; } index.html is valid XHTML 1.0 Strict and style.css is valid CSS. iefix.css does not validate because expression is something IE specific and is therefore not in the specification. It is tested in FF 2.0.0.4, Opera 9.21 and IE 7. [attachment deleted by admin]
-
I don't see any problems (FF 2.0.0.4). Besides, you shouldn't use tables for that.
-
keeB: You don't need methods to be static in order to use parent::
-
That's too insecure. I can just set my cookie to the id of the admin, then I can edit his/her profile...
-
In the event of a variable being encorporated into the code is the above method accepated for having the hyperlink url in a variable? Yes, but I prefer to put curly brackets around the variable (see below example). That'll allow you to use arrays in it too, I don't think it will otherwise. Also note that double quotes are required if you need it to parse variables, line breaks (\n), tabs (\t) etc. <?php echo "bla bla {$var['something']}"; ?>
-
It DOES make a new line ( \n ), but not an HTML line break ( <br /> ).
-
What error are you getting (if any)? What web server are you using (Apache, IIS, ...)?
-
If you place your file in e.g. /home/somebody/public_html/index.php then you'd access it like http://example.com/index.php (or just http://example.com).
-
I'd have to say number two, number one simply hurts my eyes a bit when I'm looking at it. For number 2: You should consider centering it, on widescreen monitors there is a huge gap to the right side. You should also improve the gradient in the background. Perhaps preload the hover images for the tabs in some way, with slower connections there is a wait time before it changes because it has to download a new image. [attachment deleted by admin]