Jump to content

fyurien

New Members
  • Posts

    5
  • Joined

  • Last visited

fyurien's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I was able to modify your code a bit and it seemed to work... <?php $hostdb = 'localhost'; $dbname = 'your_DB'; $username = 'root'; $password = ''; $table = 'YOURTABLE'; $pdo = new PDO("mysql:host=$hostdb;dbname=$dbname", $username, $password); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //modified this line below// $sql = "SELECT name FROM $table ORDER BY RAND() LIMIT 2;"; $stmt = $pdo->prepare($sql); $stmt->execute(); $result = $stmt->fetchAll(); echo '<pre>'; print_r($result); echo '</pre>'; ?>
  2. Holy wow, that's way more complicated than I thought it would be. I will pull a Captain America here an say I understand most of those references. As an aside I stuck that into my program and it seemed to work. Generated a bunch of stuff. I think the entire table actually
  3. Ok cool. So I can see how to make a connection using PDO... but no clue how to replicate the rest of the function. I have no programming skills unfortunately. Would you be able to help me make sense of it?
  4. Here's what I was able to find... https://www.w3schools.com/php/func_mysqli_query.asp Am on the right track?
  5. Hey all, First I know basically 0 about programming, so forgive the obvious mistakes. I have a simple (at least I thought script) that worked in php 5, but no go in php 7. I tried upgrading it to php 7, but can't get it to work. Can someone please help me. <?php function sentence() { global $post; mysqli_connect("localhost", "user", "pass", "database"); mysqli_query('set names "utf8"'); $query="SELECT name FROM seo ORDER BY RAND() LIMIT 10;"; $result=mysqli_query($query); $num=mysqli_num_rows($result); //Begin find and replace while($row = mysqli_fetch_array($result)) { //this is the string to look into $myString = $row['name']; //this is the thing to look for $patterns = array(); $patterns[0] = '/1111/'; //this is what you replace it with $result1 = $post->post_title; //this is the echo echo preg_replace_callback($patterns, $result1, $myString); } mysqli_close(); } ?> Thank you in advance
×
×
  • 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.