Jump to content

Search the Community

Showing results for tags 'ctype'.

  • 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 1 result

  1. I am pulling some data out of a MySQL database and echoing it out (pretty standard stuff) What is really confusing me is I have checked the query using phpMyAdmin and it returns 1 row which is what i expect. I've even double checked by using a COUNT query and i get the same result. The problem is when I run the returned array through a foreach loop to populate a new array, it appears to create 2 new array rows and i think it's to do with my IF statements. What i want to do in the IF is check is a certain value is present. If not, check that the value is a number and a certain length out of 2 conditions. If not, then do nothing. I'm looking for 3 conditions. Could the problem be that the field type in the database is a varchar and i'm checking for a number? Here is my code $allowed = array('param1', 'param2', 'param3'); //if(isset($_POST['submit'])) { //$sql = 'SELECT consignment_number FROM tracker WHERE order_number = 2893214 AND consignment_number IS NOT NULL'; $sql = 'SELECT column1, column2 FROM table WHERE column1 = :placeholder AND CHAR_LENGTH(column2) > 1'; $stmt = $db->prepare($sql); //$stmt->bindValue('order', $_POST['order']); $stmt->bindValue(':placeholder', $val); $stmt->execute(); $rows = $stmt->fetchAll(); echo count($rows).'<br />'; //echos 1 as checked in phpMyAdmin if(count($rows) != 0) { $myarray = array(); foreach($rows as $row) { $test = $row['column2']; //do something if ($test == 'RM') { // despatched by royal mail $myarray['column1'] = "param1"; $myarray['column2'] = $test; } elseif ( ctype_digit($test) && (strlen($test) == ) { // going by FedEx? $myarray['column1'] = "param2"; $myarray['column2'] = $test; } elseif ( ctype_digit($test) && (strlen($test) == 11) ) { // going by TNT? $myarray['column1'] = "param3"; $myarray['column2'] = $test; } } } else { //no rows } echo count($myarray); echo '<pre>';var_dump($myarray);echo'</pre>'; if(in_array($myarray['column1'], $allowed)) { foreach ($myarray as $array) { if(!empty($myarray['column1'])) { echo $myarray['column1'].': '.$myarray['column2'].'<br />'; } } } else { }
×
×
  • 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.