Jump to content

Search the Community

Showing results for tags 'if/else'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 3 results

  1. I'm having two issues: (1) The correct mysql query for multiple rows (2) The if/elseif/else to pull data from these rows, and process it based on the row data I'm only pulling data where A=1 and B=1,2 -- so two possible entries there (call them B1 and B2). I need a php if statement to choose whether the output of B is one of two urls (b1=google,b2=bing). The actual script is far more complex, with more than just 1,2 from B. I've stripped all the excesses down to this one if/else issue and the db query. The output php doesn't matter here. And I can add more elseif once this problem is solved. <?php mysql_connect(localhost, $db_username, $db_password); @mysql_select_db($db_database) or die("No connection"); $query = "Select * FROM table WHERE column='stuff' AND parent='1,2' ORDER BY id DESC LIMIT 10"; $query_result = mysql_query($query); $num_rows = mysql_num_rows($query_result); mysql_close(); ?> <?php for($i=0; $i< $num_rows; $i++){ //start a loop $stuff = mysql_result($query_result, $i, "column"); $row = mysql_fetch_assoc($query_result, $i); if($row['parent'] == 1) { $url = 'http://google.com'; } else { $url = 'http://www.bing.com'; } ?> My own first attempt at a if/then was 500. I got help on another site to redo it (new code shown here), but the new if/else always show the else (Bing). It was also at this time that I learned that "1,2" only showed 1. Hoping that this site is far more friendly than StackOverflow. .
  2. I am temporarily including some extra "testing" code within my program to help me troubleshoot it. It won't be in the final program. I'm trying to compare the correct answer in a quiz program ($ans) with the user's answer ($_POST['guess']). Even when the user picks the right answer, the program still spits out, "wrong!" I am not seeing my logical error here, but I obviously have one. I attached a screen shot of the output. I hope it helps. Thank you all. if (isset($_POST['qid'])){ //qid is the question id $_SESSION['qid']=$_POST['qid']; print_r($_SESSION); $ans = $db->query("SELECT answer FROM QuestionsAnswers WHERE questionid = " . $_SESSION['qid']); echo "<br />"; print_r ($ans); //correct answer while($row = $ans->fetch(PDO::FETCH_ASSOC)) { echo "<p>Here is my Thursday 6pm attempt:xxx" . intval($row['answer']) . "xxx</p>"; echo "<p>User guessed:xxx" . intval($_POST['guess']) . "xxx</p>"; echo '<p>the extra exes ("xxx") are to demonstrate there are no spaces in the field data.</p>'; } if (intval($row['answer']) == intval($_POST['guess'])){ //values converted to integers just in case one or both is/are a string echo "<p>Right!</p>";} else{ echo "<p>wrong!</p>"; } It is bugging me that PHPFreaks won't let me log into my regular account. Cool. At least I can log in using Facebook. Different account, same person. It is still me. Thanks to all for any help with this one. (please see attached output.)
  3. Can someone tell me if this is excessive use of IF statement? Thanks. if ($role == 'admin') { // Check if the user exist if (isset($_POST['user_email']) && !empty($_POST['user_email'])) { // Sanitize the data $user_email_data = trim(strip_tags(stripslashes($_POST['user_email']))); // Now use PHP to check for validation if (filter_var($user_email_data, FILTER_VALIDATE_EMAIL)) { if (false == get_user_by('email', $user_email_data)) { // the user doesn't exist } else { // the user exists update_user_meta($userID, 'wp_user_roles', '10'); // check wp if the new value has been stored if (get_user_meta($userID, 'wp_user_roles', true) != '10') { wp_die('An error occured!'); } } } } } else { // Do nothing, exit exit ; }
×
×
  • 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.