Jump to content

dropfaith

Members
  • Posts

    1,141
  • Joined

  • Last visited

About dropfaith

  • Birthday 10/04/1980

Contact Methods

  • Website URL
    http://dropfaithproductions.com

Profile Information

  • Gender
    Male

dropfaith's Achievements

Advanced Member

Advanced Member (4/5)

0

Reputation

  1. so i know this is an easy one i just cant recall how or what to search to make it work been a bit since ive coded php right now it does everything needed but im trying to clean up the display a bit the echo line just loops the tr and tds endlessly to the left and right What im going for would be more like this Current Result <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> <td>5</td> <td>6</td> <td>7</td> <td>8</td> </tr> Result i need <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> </tr> <tr> <td>5</td> <td>6</td> <td>7</td> <td>8</td> </tr> and so on Code below $sql = "SELECT * FROM hashtag"; if($result = mysqli_query($link, $sql)){ if(mysqli_num_rows($result) > 0){ while($row = mysqli_fetch_array($result)){ echo "<td><h1>" . $row['text'] . "</h1><img src=" . $row['link'] . "></td>"; } // Free result set mysqli_free_result($result); } else{ echo "No records matching your query were found."; } } else{ echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); } right now
  2. that fixed that any way to reverse a foreach.. it displays from twitter so the loop is newest first and cycles thus replacing the newest of the tags otherwise i can just dump the foreach loop and have my bot look thru the script more often thus eliminating its need but adding server strain foreach ($user_timeline as $user_tweet) { if (isset($user_tweet->entities->media)) { $media_url = $user_tweet->entities->media[0]->media_url; $hashtag = preg_replace('^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-‌​\.\?\,\'\/\\\+&%\$#_]*)?$^',' ', $user_tweet->text); } /* Attempt MySQL server connection. Assuming you are running MySQL server with default setting (user 'root' with no password) */ $link = mysqli_connect("localhost", "roguebro", "eruditio2", "roguebro_tweet"); // Check connection if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); } // Attempt insert query execution $sql = "INSERT INTO hashtag (hashtag, link) VALUES ('$hashtag', '$media_url') ON DUPLICATE KEY UPDATE link='" . $media_url . "'"; if(mysqli_query($link, $sql)){ echo "Records inserted successfully."; echo ($sql); echo "<br>"; } else{ echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); } }
  3. hrmm producing an error in this and i thought i had it ERROR: Could not able to execute (INSERT INTO hashtag (hashtag, link) VALUES ('arena ', 'http://pbs.twimg.com/media/C5QtXQEVUAAyk_-.jpg') ON DUPLICATE KEY UPDATE link='http://pbs.twimg.com/media/C5QtXQEVUAAyk_-.jpg'). You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'INSERT INTO hashtag (hashtag, link) VALUES ('arena ', 'http://pbs.twimg.com/med' at line 1 /* Attempt MySQL server connection. Assuming you are running MySQL server with default setting (user 'root' with no password) */ $link = mysqli_connect("localhost", "roguebro", "", "roguebro_tweet"); // Check connection if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); } // Attempt insert query execution $sql = "(INSERT INTO hashtag (hashtag, link) VALUES ('$hashtag', '$media_url') ON DUPLICATE KEY UPDATE link='" . $media_url . "')"; if(mysqli_query($link, $sql)){ echo "Records inserted successfully."; } else{ echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); } // Close connection mysqli_close($link);
  4. Sorry i did that on no sleep at 5 am basically right now it inserts a new row everytime the script runs which isnt ideal for the end game anymore i changed up my other side to fit it better theres 3 columns Id (auto inc) hashtags and link what i need is if hashtag exists edit link to the new link field there will never be more then 1 link in for each hashtag. i know it has something in here and an update instead of insert but im literally clueless on syntax for it function insertTweets($link,$hashtag){ $mysqli = new mysqli(DBHOST, DBUSERNAME, DBPASSWORD, DBNAME); if ($mysqli->connect_errno) { return 'Failed to connect to Database: (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error; } $prepareStmt='insert INTO '.DBNAME.'.'.TWEETTABLE.' (link,hashtag) VALUES (?,?)'; if ($insert_stmt = $mysqli->prepare($prepareStmt)){ $insert_stmt->bind_param('ss', $link,$hashtag); if (!$insert_stmt->execute()) { $insert_stmt->close(); return 'Tweet Creation cannot be done at this moment.'; }elseif($insert_stmt->affected_rows>0){ $insert_stmt->close(); return 'Tweet Added.<br><br>'; }else{ $insert_stmt->close(); return 'No Tweet were Added.'; } }else{ return 'Prepare failed: (' . $mysqli->errno . ') ' . $mysqli->error; } } ?> Not sure how to check the database to see if hashtag exists then update a different field and if not just insert the full query
  5. Sorry this ends this script i got it doing everything i need except its making too many rows for what i need so i figure an update to it if the hashtag field is already in no idea how to do that i am teaching myself this as i go <?php // Require J7mbo's TwitterAPIExchange library (used to retrive the tweets) // You can get this library from here: https://github.com/J7mbo/twitter-api-php require_once('TwitterAPIExchange.php'); /** database cred **/ define('DBHOST','localhost'); define('DBUSERNAME',''); define('DBPASSWORD',''); define('DBNAME','rogueweet'); define('TWEETTABLE','hashtags'); /** end database cred **/ // Set here your twitter application tokens $settings = array( 'oauth_access_token' => "831981818408677377-FeZYWt3TYwmodmx3gMmFIqx", 'oauth_access_token_secret' => "L1vwbaBjsUivKn56V1lSP5THvjBk3LiadHyOj", 'consumer_key' => "t31OianjdeBAjWPqj3", 'consumer_secret' => "zFZpwpaZl0K1CQPpsagBjVCMkTs2GtWHhRm" ); // Set here the Twitter account from where getting latest tweets $screen_name = 'Dropfaith21'; //username to mock twitter feed // Get timeline using TwitterAPIExchange $url = 'https://api.twitter.com/1.1/statuses/user_timeline.json'; $getfield = "?screen_name={$screen_name}"; $requestMethod = 'GET'; $twitter = new TwitterAPIExchange($settings); $user_timeline = $twitter ->setGetfield($getfield) ->buildOauth($url, $requestMethod) ->performRequest(); $user_timeline = json_decode($user_timeline); foreach ($user_timeline as $user_tweet) { if (isset($user_tweet->entities->media)) { $media_url = $user_tweet->entities->media[0]->media_url; $hashtag = preg_replace('^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-‌​\.\?\,\'\/\\\+&%\$#_]*)?$^',' ', $user_tweet->text); // $hashtag = $user_tweet->text; echo "($hashtag)"; echo "<img src='{$media_url}' width='60%' />"; echo insertTweets($media_url,$hashtag); } } function insertTweets($link,$hashtag){ $mysqli = new mysqli(DBHOST, DBUSERNAME, DBPASSWORD, DBNAME); if ($mysqli->connect_errno) { return 'Failed to connect to Database: (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error; } $prepareStmt='insert INTO '.DBNAME.'.'.TWEETTABLE.' (link,hashtag) VALUES (?,?)'; if ($insert_stmt = $mysqli->prepare($prepareStmt)){ $insert_stmt->bind_param('ss', $link,$hashtag); if (!$insert_stmt->execute()) { $insert_stmt->close(); return 'Tweet Creation cannot be done at this moment.'; }elseif($insert_stmt->affected_rows>0){ $insert_stmt->close(); return 'Tweet Added.<br><br>'; }else{ $insert_stmt->close(); return 'No Tweet were Added.'; } }else{ return 'Prepare failed: (' . $mysqli->errno . ') ' . $mysqli->error; } } ?>
  6. if it helps it inserts a 1 to mysql
  7. so i have the array now but cant do anything database wise. i have 4 hashtag fields and a link one the system i need to use matches array(4) { [0]=> string(19) "#ContestOfChampions" [1]=> string(7) "#Cutoff" [2]=> string(9) "#Dormammu" [3]=> string(11) "#JaneFoster" } is a sample array i would love it if i could somehow insert each field into its own mysql column to make my next steps easier
  8. echo insertTweets($items['user']['name'],$items['user']['screen_name'],$items['text'],$items['created_at'],$items['id_str'],$items['user'] ['followers_count'],$hash); /** FInd hashtags build array **/ preg_match_all("/#(\\w+)/",$items['text'],$hashtags); //now $tags is an array of hashtags /** FInd hashtags build array **/ var_dump( $hashtags); } /** Insert to database **/ function insertTweets($name,$screen_name,$text,$created_at,$id_str,$followers_count,$hash){ $mysqli = new mysqli(DBHOST, DBUSERNAME, DBPASSWORD, DBNAME); if ($mysqli->connect_errno) { return 'Failed to connect to Database: (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error; } $prepareStmt='INSERT INTO '.DBNAME.'.'.TWEETTABLE.' (name, screen_name, text, created_at, id_str, followers_count, hashtags) VALUES (?,?,?,?,?,?,?)'; if ($insert_stmt = $mysqli->prepare($prepareStmt)){ $insert_stmt->bind_param('sssssid', $name,$screen_name,$text,$created_at,$id_str,$followers_count,$hash); if (!$insert_stmt->execute()) { $insert_stmt->close(); return 'Tweet Creation cannot be done at this moment.'; }elseif($insert_stmt->affected_rows>0){ $insert_stmt->close(); return 'Tweet Added.<br>'; }else{ $insert_stmt->close(); return 'No Tweet were Added.'; } }else{ return 'Prepare failed: (' . $mysqli->errno . ') ' . $mysqli->error; } }
  9. So i got this pulling twitter data raw i cant for the life of me figure out how to explode items $text(tweet body and seperate the hashtags and enter them into a database (database hase 3 fields for hashtags) <?php /** database cred **/ define('DBHOST','localhost'); define('DBUSERNAME','***'); define('DBPASSWORD','**'); define('DBNAME','roguebro_tweet'); define('TWEETTABLE','twitter'); /** end database cred **/ /** Set access tokens here - see: https://dev.twitter.com/apps/ **/ require_once('TwitterAPIExchange.php'); $settings = array( 'oauth_access_token' => "831981818408677377-FexWOmvCyaZYWt3TYwmodmx3gMmFIqx", 'oauth_access_token_secret' => "L1vwbaBjsUivKn5NYVmGgve6V1lSP5THvjBk3LiadHyOj", 'consumer_key' => "t31OianjtopHhDEdeBAjWPqj3", 'consumer_secret' => "zFZpwrMl31BShY6CluYapaZl0K1CQPpsagBjVCMkTs2GtWHhRm" ); /** end Twitter Credentials **/ $url = "https://api.twitter.com/1.1/statuses/user_timeline.json"; $requestMethod = "GET"; $getfield = '?screen_name=MCoCTrucos&entities=on&count=20 -rt'; $twitter = new TwitterAPIExchange($settings); $string = json_decode($twitter->setGetfield($getfield) ->buildOauth($url, $requestMethod) ->performRequest(),$assoc = TRUE); if($string["errors"][0]["message"] != "") {echo "<h3>Sorry, there was a problem.</h3><p>Twitter returned the following error message:</p><p> <em>".$string[errors][0]["message"]."</em></p>";exit();} foreach($string as $items) { echo "Tweeted by: ". $items['user']['name']."<br />"; echo "Screen name: ". $items['user']['screen_name']."<br />"; echo "Tweet: ". $items['text']."<br />"; echo "Time and Date of Tweet: ".$items['created_at']."<br />"; echo "Tweet ID: ".$items['id_str']."<br />"; echo "Followers: ". $items['user']['followers_count']."<br /><hr />"; echo insertTweets($items['user']['name'],$items['user']['screen_name'],$items['text'],$items['created_at'],$items['id_str'],$items['user']['followers_count']); $tags = $items['text']; $hashtags = explode("#", $tags); } function insertTweets($name,$screen_name,$text,$created_at,$id_str,$followers_count){ $mysqli = new mysqli(DBHOST, DBUSERNAME, DBPASSWORD, DBNAME); if ($mysqli->connect_errno) { return 'Failed to connect to Database: (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error; } $prepareStmt='INSERT INTO '.DBNAME.'.'.TWEETTABLE.' (name, screen_name, text, created_at, id_str, followers_count) VALUES (?,?,?,?,?,?);'; if ($insert_stmt = $mysqli->prepare($prepareStmt)){ $insert_stmt->bind_param('ssssid', $name,$screen_name,$text,$created_at,$id_str,$followers_count); if (!$insert_stmt->execute()) { $insert_stmt->close(); return 'Tweet Creation cannot be done at this moment.'; }elseif($insert_stmt->affected_rows>0){ $insert_stmt->close(); return 'Tweet Added.<br><br>'; }else{ $insert_stmt->close(); return 'No Tweet were Added.'; } }else{ return 'Prepare failed: (' . $mysqli->errno . ') ' . $mysqli->error; } } ?>
  10. So i got the basis of this working here http://www.roguebrother.x10host.com/tweet.php what im trying to do is make it so it searches by not only username(complete) but also a certain hashtag (Duels) And get it to display any media (photos) in said tweet <?php require_once('TwitterAPIExchange.php'); /** Set access tokens here - see: https://dev.twitter.com/apps/ **/ $settings = array( 'oauth_access_token' => "831981818408677377-FexWOmvCyaZYWt3TYwmodmx3gMmFIqx", 'oauth_access_token_secret' => "L1vwbaBjsUivKn5NYVmGgve6V1lSP5THvjBk3LiadHyOj", 'consumer_key' => "t31OianjtopHhDEdeBAjWPqj3", 'consumer_secret' => "zFZpwrMl31BShY6CluYapaZl0K1CQPpsagBjVCMkTs2GtWHhRm" ); $url = "https://api.twitter.com/1.1/statuses/user_timeline.json"; $requestMethod = "GET"; $getfield = 'screen_name=MCoCTrucos&count=1'; $twitter = new TwitterAPIExchange($settings); $string = json_decode($twitter->setGetfield($getfield) ->buildOauth($url, $requestMethod) ->performRequest(),$assoc = TRUE); if($string["errors"][0]["message"] != "") {echo "<h3>Sorry, there was a problem.</h3><p>Twitter returned the following error message:</p><p> <em>".$string[errors][0]["message"]."</em></p>";exit();} foreach($string as $items) { echo "Tweeted by: ". $items['user']['name']."<br />"; echo "Screen name: ". $items['user']['screen_name']."<br />"; echo "Tweet: ". $items['text']."<br />"; echo "Time and Date of Tweet: ".$items['created_at']."<br />"; echo "Tweet ID: ".$items['id_str']."<br />"; echo "Followers: ". $items['user']['followers_count']."<br /><hr />"; } { echo $url;} ?>
  11. this below is the idiot error it submits everything except baby into my database just fine baby = select box like all the others html is fine <?php $gender = $_POST['gender']; $gender1 = $_POST['gender1']; $Species1 = $_POST['Species1']; $Species2 = $_POST['Species2']; $baby = $_Post['baby']; $query="insert into breeding (gender, gender1, Species1, Species2, baby) values ('$gender','$gender1','$Species1','$Species2','$baby')"; $result = mysql_query($query); ?> Okay now for the question the code below im trying to add a counter to it but all the fields need to match so anytime all gender 1 and 2 species 1 and 2 baby match it adds to a counter and displays but only if they all match. Im not sure where to start on that so tips are awesome or instruction since im new to this <?php $query = "SELECT * FROM breeding"; $result = mysql_query($query); if (mysql_num_rows($result) > 0) { // iterate through resultset // print article titles while($row = mysql_fetch_object($result)) { ?> <tr> <td><?php echo $row->gender; ?> <?php echo $row->Species1; ?></td> <td><?php echo $row->gender1; ?> <?php echo $row->Species2; ?></td> <td><?php echo $row->baby; ?></td> <td>HERE ID LIKE TO ECHO TOTAL </td> </tr> <?php } } // if no records present // display message else { ?> <p>No press releases currently available</p> <?php } ?> http://box1.host1free.com/~crimso/breeding.php theres a test link
  12. Relevant Links http://www.treasuretrooper.com/api/116fcbdb1cac242e789a892ebd2a0abb/treasure/xml http://box1.host1free.com/~crimso/index.php (right side My Treasure section) <?php function getPagetreasure($url="http://www.treasuretrooper.com/api/116fcbdb1cac242e789a892ebd2a0abb/treasure/xml"){ $ch = curl_init(); curl_setopt($ch,CURLOPT_URL, $url); curl_setopt($ch,CURLOPT_FRESH_CONNECT,TRUE); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,5); curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE); curl_setopt($ch,CURLOPT_REFERER,'http://www.treasuretrooper.com/'); curl_setopt($ch,CURLOPT_TIMEOUT,10); $xmltreasure=curl_exec($ch); if($xmltreasure==false){ $m=curl_error(($ch)); error_log($m); } curl_close($ch); return $xmltreasure; } $xmlfiletreasure = getPagetreasure("http://www.treasuretrooper.com/api/116fcbdb1cac242e789a892ebd2a0abb/treasure/xml"); $treasure =new SimpleXMLElement($xmlfiletreasure); $resultst = array(); foreach ($treasure as $ttreasure){ $resultst[] = $ttreasure; } print_r($resultst); ?> I have it printing the array so you guys can see whats in it.. What im trying to do is build a simple 2 column table ie <table> <tr> <td class="label">Offer Due</td> <td>DATA FROM ARRAY HERE.</td> </tr> </table> i wont be using all the data in the array on this project prob like 4 items total Offer_Due, Total_Due,Total_Paid and maybe a few more as time goes on im clueless as to where to go from where my php is to where i need it to go at this point
  13. I wont lie i legit have no idea what your talking about on that lol. Im pretty much teaching myself this as i go i dont use php ever.. Started like last night ish
  14. Warning: array_reverse() [function.array-reverse]: The argument should be an array in /home/crimso/domains/crimsontrauma.com/public_html/template/rightnav.php on line 38
×
×
  • 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.