0

I'm looking for a way to run this script through a table in my MySQL database.

  1. Firstly, how do I define the table in which to loop this script?
  2. How do I add the result of get_httpcode into another field in the record, 'imgstatus'?

Are there any better ways of approaching this?

<?php 

// Create connection
$con=mysqli_connect("xxxx","xxxx","xxxx","xxxx");

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

function get_httpcode($url) {
    $headers = get_headers($url, 0);
    // Return http status code
    return substr($headers[0], 9, 3);
  }

    while($data = mysql_fetch_assoc($sql)):

      $result = get_httpcode('http://'.$data['img']);   
      echo $data['img'].' = '.$result.'<br/>';

    endwhile;

?>
1
  • 3
    I think your code do nothing, there is no query executed, also running mysql_fetch_assoc over mysqli_connect if not possible Commented Jan 16, 2014 at 10:56

1 Answer 1

1

1 - First you have to actually define a table to run your query like : create table tablename(...);

2 - Then you must write a sql query to get the data out of your table

3 - Then you have to define what $data is

4 - Then you should delete endwhile statement

5 - Then you should fix get_httpcode function because it will always return the 0th element in the header, most probably the http return code.

For simple examples, start with below:

1 - http://www.php.net/manual/en/mysql.examples-basic.php

2 - http://www.freewebmasterhelp.com/tutorials/phpmysql

Sign up to request clarification or add additional context in comments.

1 Comment

Can you point me to any examples where something similar to my requirements has been created? Eager to learn J

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.