Jump to content

sasa

Staff Alumni
  • Posts

    2,804
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by sasa

  1. try <?php $result = mysql_query("SELECT id, sandwich, price FROM sandwiches"); //echo mysql_num_rows($result) . '<br>'; //Sif($result){ echo '1'; } else { echo '2'; } // Print the titles echo '<table width="28%" border="0" cellspacing="2" cellpadding="0"> <tr> <td width="50%" height="3" align="center"><strong>Sandwich</strong></td> <td width="50%" height="3" align="center"><strong>Price</strong></td> </tr>',"\n"; //fetch tha data from the database while ($row = mysql_fetch_array($result)) { echo '<tr><td width="50%" height="3" align="center">'.$row['sandwich'].'</td> <td width="50%" height="3" align="center">'.$row['price'].'</td></tr>',"\n"; } echo '</table>'; //close the connection mysql_close($dbhandle); ?>
  2. change line <td><? $myid=$rows['id']; echo "<input name='$myid' type='checkbox' id='$myid'>"; ?></td> to <td><? $myid=$rows['id']; echo "<input name='id[]' value='$myid' type='checkbox' id='$myid'>"; ?></td> and in next page print_r($_POST['id']);
  3. ups <?php $query = "SELECT * FROM modlpae WHERE userid = '$user'"; $result = mysql_query($query) or die('Error : ' . mysql_error()); $total_questions = 15; while ($row = mysql_fetch_assoc($result)) { $filled = 0; for ($qcounter = 1; $qcounter <= $total_questions; $qcounter++){ if(!is_null($row["q".$qcounter]) and $row["q".$qcounter] != '') $filled++; } echo $percentage = ($filled/$total_questions)*100,"%\n"; } ?> change or to and
  4. try <?php $query = "SELECT * FROM modlpae WHERE userid = '$user'"; $result = mysql_query($query) or die('Error : ' . mysql_error()); $total_questions = 15; while ($row = mysql_fetch_assoc($result)) { $filled = 0; for ($qcounter = 1; $qcounter <= $total_questions; $qcounter++){ if(!is_null($row["q".$qcounter]) || $row["q".$qcounter] != '') $filled++; } echo $percentage = ($filled/$total_questions)*100,"%\n"; } ?>
  5. try <?php $test = '29/02/2001'; $test = explode('/', $test); $comp = explode('/',date('d/m/Y',mktime(1,1,1,$test[1],$test[0],$test[2]))); if($test[0]==$comp[0] and $test[1]==$comp[1] and $test[2]==$comp[2]) echo 'OK'; else echo 'no'; ?>
  6. try <?php //ob_start(); $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="textgame"; // Database name $tbl_name="users"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $username = (isset($_POST['username'])) ? mysql_real_escape_string($_POST['username']) : FALSE; $password1 = (isset($_POST['password1'])) ? $_POST['password1'] : FALSE; $password2 = (isset($_POST['password2'])) ? $_POST['password2'] : FALSE; if(!$username) die('username not set'); if(!$password1) die('Password1 not set'); else $password1 = md5($password1); if(!$password2) die('Password2 not set'); else $password2 = md5($password2); $query = "SELECT * FROM users WHERE username='$username' AND password1='$password1' AND password2='$password2'"; $result = mysql_query($query) or die( mysql_error()); $count=mysql_num_rows($result); if($count==1){ session_start(); //session_register("username"); $_SESSION['username'] = $username; $queryy = "SELECT gold FROM user_stats WHERE username='$username'"; $result1 = mysql_query($queryy); $row = mysql_fetch_assoc($result1); $_SESSION['gold'] = $row['gold']; header("location:index2.php"); } else { echo "Wrong Username or Password"; } ?>
  7. <?php $arr = array(1,2,1,3,2,1,4,3,5); $arr = array_unique($arr); foreach ($arr as $v){ echo $v,"<br />\n"; } ?>
  8. look http://answers.google.com/answers/threadview/id/437751.html
  9. look <?php $num = 4.765; echo $num,"<br />\n"; echo $num - 4.76; ?>
  10. .php file can directly save information to database you don't need to send it to browser and back to server
  11. use SUM() function in SQL
  12. try <?php $test = array( array('id' => 1, 'titolo' => 'titolo1', 'weight' => 22), array('id' => 2, 'titolo' => 'titolo2', 'weight' => 1), array('id' => 3, 'titolo' => 'titolo3', 'weight' => 21) ); function my_comp($a, $b){return $a['weight'] - $b['weight'];} usort($test, 'my_comp'); print_r($test); ?>
  13. ups <?php $names = array_chunk($names, $rowsperpage); $names = $names[$currentpage - 1]; //add your code here ?>
  14. try <?php $names = array_chunk($names, $rowsperpage); $names = $names[$currentpage]; //add your code here ?> but better is using limit in query
  15. http://www.php.net/error_reporting RTFM
  16. change <a href="<?php $ad['url']['0'] ?>"><img src="<?php $ad['ad']['0'] ?>"></img></a><br /> to <a href="<?php echo $ad['url']['0']; ?>"><img src="<?php echo $ad['ad']['0']; ?>"></img></a><br /> etc.
  17. SELECT * from `table name` where (Wins + Losses) > 0 ORDER BY Wins / (Wins + Losses) DESC LIMIT 30
  18. try $startmonth = 12; $startyear = 2007; $endmonth = 11; $endyear = 2010; $completedyear = 0; for ($i = $startyear *12 + startmont; $i <= $endyear *12 + $endmonth; $i++){ echo $i % 12, '-', (int) ($i / 12); }
  19. change to <?php /* Set e-mail recipient */ $myemail = "mywebdots@gmail.com"; /* Check all form inputs using check_input function */ $yourname = check_input($_POST['yourname'], "Enter your name"); $subject = check_input($_POST['subject'], "Write a subject"); $email = check_input($_POST['email']); $address = check_input($_POST['address']); $product = check_input($_POST['product']); $screens = check_input($_POST['screens']); $how_find = check_input($_POST['how']); $from = check_input($_POST['email']); $comments = check_input($_POST['comments'], "Write your comments"); print '<pre>'; print_r($_POST); print '</pre>'; /* If e-mail is not valid show error message */ if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) { show_error("E-mail address not valid"); } /* Let's prepare the message for the e-mail */ $message = "Hello!, Your contact form has been submitted by: Name: $yourname E-mail: $email Address: $address Which products I am interested in?"; // add " $message .= "<ul>"; foreach($_POST['product'] as $key=>$val){ $message .= "<li>".$val."</li>"; } $message .= "</ul>"; // add next line $message .= " How did he/she find it? $how_find Comments: $comments End of message "; /* Send the message using mail() function */ mail($myemail, $subject, $message, "From: $from"); /* Redirect visitor to the thank you page */ header('Location: thanks.htm'); exit(); /* Functions we used */ function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?> <html> <body> <b>Please correct the following error:</b><br /> <?php echo $myError; ?> </body> </html> <?php exit(); } ?>f/code]
  20. try SELECT * FROM `proba` WHERE SUBSTRING( name, LOCATE( ' ', name ) +1 ) LIKE 'K%'
  21. <?php $text = '<tr>'; $big_number = strlen($text); $res = ($x = min(($b = strpos($text, '<li'))===false ? $big_number:$b,($b = strpos($text, '<tr'))===false ? $big_number:$b))== $big_number ? false : $x; echo var_dump($res); ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.