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 4 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 ; }
  4. For SEO purposes, I need to have a different header for the different portfolio pages generated on the following site: The primary page http://tcnyc.com/portfolio.php invokes the following, based on vf_category: http://tcnyc.com/por...egory=Bathrooms http://tcnyc.com/por...tegory=Kitchens The code at portfolio_category.php uses the following to set the header: //Show header $template_header = new HTML_Template_IT(); $template_header->loadTemplateFile("parts/header.tpl",true,false); $template_body->setVariable('header', $template_header->get()); The problem is the 2nd item, where parts/header.tpl is fixed. I need to use Bathroomsheader.tpl for bathrooms, Kitchensheader.tpl for kitchens, etc. (or some similar nomenclature). This is because the header (with Title & Description tags) needs to change based on category. The existing code is: <?php $vc_root_friendly = '.'; $vc_root_site = '.'; include_once("$vc_root_site/config.php"); include_once("$vc_includes_folder/IT.php"); $template_body = new HTML_Template_IT(); $template_body->loadTemplateFile("tpl_portfolio_category.html"); include_once("$vc_includes_folder/images.php"); if(!isset($_REQUEST['vf_category'])){ header("location:portfolio.php"); die(); } //Show header $template_header = new HTML_Template_IT(); $template_header->loadTemplateFile("parts/header.tpl",true,false); $template_body->setVariable('header', $template_header->get()); //Show footer $template_footer = new HTML_Template_IT(); $template_footer->loadTemplateFile("parts/footer.tpl",true,false); $template_body->setVariable('footer', $template_footer->get()); $template_body->setVariable("image_category", $_REQUEST['vf_category']); //Select photos for this category $vl_photos = $DB->q("SELECT * FROM $vc_prefix"."photo_gallery WHERE category = '$_REQUEST[vf_category]' ORDER BY id_photo"); //Show photos etc. Does anyone know how to modify this code such that the vf_category pulled from the database can cause includes of the correct header.tpl? I know that it will involve if & else commands, i.e., if vf_category = Bathrooms, then use header name A, else use head name B, etc. Thanks in advance! gckmac
×
×
  • 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.