cobusbo
-
Posts
224 -
Joined
-
Last visited
Posts posted by cobusbo
-
-
Hi I'm currently using a header to retrieve some info
$prof = $_SERVER["HTTP_X_MXIT_PROFILE"];
It output the value as
en,ZA,1991-01-30,Male,1I'm trying to use the 1991-01-30 from the above output to calculate if the person is 18 years of age or older
Any suggestions on how to do this I tried to put it into an array but was unsuccessful...
-
You would call your function like any other function
$this->ip = getUserIP();
Or if getUserIP is a method for your poll class then it'll be
$this->ip = $this->getUserIP();
Ah thank you I see I had the same function on both pages and got redeclare error so I fixed it
-
Hi I got two functions and I want to use the 2nd function within the first function is this possible
Function 1
class poll { public $db; public $tbl; public $pollvars; public $poll_view_html; public $poll_result_html; public $options; public $options_text; public $poll_question; public $form_forward; public $template_set; public $ip; public function __construct() { global $POLLTBL, $CLASS; $this->tbl = $POLLTBL; $this->poll_view_html = array(); $this->poll_result_html = array(); $this->options = array(); $this->options_text = array(); $this->poll_question = array(); $this->form_forward = basename($_SERVER['PHP_SELF']); $this->ip = getenv("REMOTE_ADDR"); $this->db = &$CLASS["db"]; $this->pollvars = $this->db->fetch_array($this->db->query("SELECT * FROM ".$this->tbl['poll_config'])); $this->template_set = "default"; if ($this->pollvars['result_order'] == "asc") { $this->pollvars['result_order'] = "ORDER BY votes ASC"; } elseif ($this->pollvars['result_order'] == "desc") { $this->pollvars['result_order'] = "ORDER BY votes DESC"; } else { $this->pollvars['result_order'] = ''; } }
Function 2
function getUserIP() { $mxitidun = $_SERVER['HTTP_X_MXIT_DEVICE_ID']; $client = @$_SERVER['HTTP_CLIENT_IP']; $forward = @$_SERVER['HTTP_X_FORWARDED_FOR']; $remote = $_SERVER['REMOTE_ADDR']; if($mxitidun != '') { $ip1 = $mxitidun; } elseif(filter_var($client, FILTER_VALIDATE_IP)) { $ip1 = $client; } elseif(filter_var($forward, FILTER_VALIDATE_IP)) { $ip1 = $forward; } else { $ip1 = $remote; } return $ip1; }
I'm trying to Use the line in function 1
$this->ip = getenv("REMOTE_ADDR");
and replace getenv("REMOTE_ADDR"); with the function output value of Function 2
-
I think I see what you want now. You need to find the highest id associated with each topic and sort on that.
$sql = "SELECT topic , description , topid FROM news INNER JOIN ( SELECT topic , MAX(id) as topid FROM news GROUP BY topic ) tid USING (topic) ORDER BY topid DESC, id ASC"; $res = $db->query($sql); $prevtopid = ''; while ($row = $res->fetch_assoc()) { if ($prevtopid != $row['topid']) { echo "<b>{$row['topic']}</b><br>"; $prevtopid = $row['topid']; } echo " - {$row['description']}<br>"; }
Results
barand - test - test 2 jogom - naaaaa moo - meee Hahaha - ???? Test Heading - Test - Hmmmm 100%!!! - Test description
Thank you, I figured another way aswell just now. I added another field in my database named rank(numbers) and add a a new value each time into the field each time I create a topic and changed my display loop to work with the rank instead of the topics. But I'm going to use the above code
-
Exactly.
So there isn't a way to sort it by ID?
Here Is my current display page...
100%!!! - Edit Topic | Add Descr | DEL* Test description - Edit Descr | Delbarand - Edit Topic | Add Descr | DEL* test 2 - Edit Descr | Del* test - Edit Descr | DelHahaha - Edit Topic | Add Descr | DEL* ???? - Edit Descr | Deljogom - Edit Topic | Add Descr | DEL* naaaaa - Edit Descr | Delmoo - Edit Topic | Add Descr | DEL* meee - Edit Descr | DelTest Heading - Edit Topic | Add Descr | DEL* Hmmmm""" - Edit Descr | Del* Test - Edit Descr | DelDatabase Table LayoutID Topic Description Date2 Test Heading Test 14428264713 100%!!! Test description 14428265468 Test Heading Hmmmm""" 14428265309 Hahaha ???? 144282733211 moo meee 144284270912 jogom naaaaa 144284303113 barand test 144284539114 barand test 2 1442845636I want it to show like
barand - Edit Topic | Add Descr | DEL* test - Edit Descr | Del* test 2 - Edit Descr | Deljogom - Edit Topic | Add Descr | DEL* naaaaa - Edit Descr | Delmoo - Edit Topic | Add Descr | DEL* meee - Edit Descr | DelHahaha - Edit Topic | Add Descr | DEL* ???? - Edit Descr | DelTest Heading - Edit Topic | Add Descr | DEL* Hmmmm""" - Edit Descr | Del* Test - Edit Descr | Del100%!!! - Edit Topic | Add Descr | DEL* Test description - Edit Descr | DelSo basically I want my topics column to be ordered DESC according to ID and my News column ordered ASC -
ORDER BY topic, id DESC
or, if you want topics descending too,
ORDER BY topic DESC, id DESC
The thing is it still order the topics column first, I want to sort the ID column first and then the topics column, but if I change it to
ORDER BY id DESC, topic
my topics and descriptions isn't grouped no more?
-
prev = ''; while fetch next row if prev != topic output topic prev = topic endif output news endwhile
Thank you @Barand I got it working
$sql = "SELECT * FROM News ORDER BY topic"; if (in_array($testip, $admin)) { echo $addnew . "<br><br>"; $lasttopic = ''; while($myrow = mysql_fetch_array($result1)) { $id = $myrow["id"]; $topic = $myrow["topic"]; if ( $lasttopic != $myrow['topic'] ) { print "<b>" . $myrow['topic'] . "</b> - " . $Edittopic . " | " . $adddescr . " | " . $deletetopic . "<br>"; $lasttopic = $myrow['topic']; } print "<p>* " . $myrow['news'] . " - " . $Editnews . " | " . $delete . "<br></p>"; }
Just a question since im ordering it by Topic how will I add Descending order by id to show the latest topic and description at the top?
-
I'm getting the output
How to show it as
1
* 99
* 100
2
* 1000
* 2000
$sql = "SELECT * FROM News ORDER BY topic"; $result1 = mysql_query($sql, $db)or die($sql."<br/><br/>".mysql_error()); while($myrow = mysql_fetch_array($result1)) { print $myrow['topic'] . " - " . $Editnews . "<br>"; print $myrow['news'] . " - " . $Editnews. "<br>"; }
Any assistance please?
-
If 1 and 99 and 1000 and 2000 all are the same field and are NUMERIC (not text) that will be difficult.
I used 1 and 2 as the topics and 99 and 100 as the description of 1(topic) and 1000 and 2000 description of 2(topic)
-
GROUP BY in the query doesn't do that. it consolidates the rows having the same group value into a single row. it's primarily used when you want to use aggregate functions (sum, count, ...) on the data in the group.
to do what you are asking, you would order (use ORDER BY topic) the rows in the result set to get the rows for the same topic together, then when you are outputting the data, each time the topic value changes you would close out the previous topic section and start a new topic section.
I'm getting the output
1 - Edit News
99 - Edit News1 - Edit News100 - Edit News2 - Edit News1000 - Edit News2 - Edit News2000 - Edit NewsHow to show it as
1
* 99
* 100
2
* 1000
* 2000
$sql = "SELECT * FROM News ORDER BY topic"; $result1 = mysql_query($sql, $db)or die($sql."<br/><br/>".mysql_error()); while($myrow = mysql_fetch_array($result1)) { print $myrow['topic'] . " - " . $Editnews . "<br>"; print $myrow['news'] . " - " . $Editnews. "<br>"; }
-
Hi I have the following fields in my database table
id - int
topic - varchar
news - varchar
What im trying to do is group the topics ex
topic1 - 123
topic2 - 987
topic1 - 456
topic2 - 654
I want to show it as
Topic 1
* 123
* 456
Topic 2
* 987
* 654
seems like I'm going wrong somewhere...
$sql = "SELECT * FROM News GROUP BY topic"; $result1 = mysql_query($sql, $db)or die($sql."<br/><br/>".mysql_error()); while($myrow = mysql_fetch_array($result1)) { print $myrow['topic'] . " - " . $Editnews . "<br>"; print $myrow['news'] . " - " . $Editnews. "<br>"; }
-
Hi I'm trying to find a script where I can create my own topics and descriptions to use as a news page or notification board
with the layout like
Heading 1 - Edit | Delete | Down
- Description 1 - Edit | Delete | Down
- Description 2 - Edit | Delete | Up | Down
- etc...
Heading 2 - Edit | Delete | Up
- Description 1 - Edit | Delete | Down
- Description 2 - Edit | Delete | Up | Down
- etc...
etc...
It should be able to add as many headings and descriptions as you wish ad an option next to each one to edit the heading or description
Does anyone know of a sortlike script?
-
Hi I'm trying to create a mute function
My Database table layout:
ID int AI
word varchar 30
I got 260 words in my table now I'm trying to check my $_POST['message'] string to see if any of these words are in the string and if it does it should insert a 10 min mute
$resultmute = mysql_query("SELECT word FROM StringyChat_WordBan") or die(mysql_error()); $rowmute = mysql_fetch_assoc($resultmute); if (stristr($message,$rowmute['word']) !== false) { $expire = time() + (60 * 10); $querymute = "UPDATE timeban SET user='$name', bantime='$expire', banby='ADMIN' WHERE mxitid='".$mxitid."'"; mysql_query($querymute); }
The current problem I have is I want to check case insensitive characters. For instance if I got the word "badwords" in the database and the word is spelled "Badwords" it should still be considered a bad word. At the moment it seems like only certain words in my database get filtered and the rest not...
My second question is regarding the replacing of the word with this function
function filterBadWords($str) { $result1 = mysql_query("SELECT word FROM StringyChat_WordBan") or die(mysql_error()); $replacements = "x"; while($row = mysql_fetch_assoc($result1)) { $str = preg_replace('/\b' . $row['word'].'\b/i', ':-x', $str); } return $str; }
Is there a way to check if theres another letter next to the word and if so not to filter it. for example assassinate will be filtered to :-x:-xinate but I want to check if there is some character at the end or the beginning of the same word not to filter it...
-
Hi I'm currently having a syntex error with my bad words filter function
function filterBadWords($str) { $result1 = mysql_query("SELECT word FROM StringyChat_WordBan") or die(mysql_error()); $replacements = "x"; while($row = mysql_fetch_assoc($result1)) { $str = preg_replace('/\b' . $row['word'].'\b/ie', ':-x', $str); } return $str; }
Parse error: syntax error, unexpected ':' in /home/u342037492/public_html/chat2/page.php(1917) : regexp code on line 1
Fatal error: preg_replace(): Failed evaluating code: :-x in /home/u342037492/public_html/chat2/page.php on line 1917I know its the :-x part causing the problem but how can I fix it?
and is there maybe a better way to do the filter because if I got the word "ass" in my list it will replace assassinate to :-x :-xinate ?
-
$marray = array( '1' => 'apple,', '2' => 'orange,', '3' => ' ', '4' => ' ', '5' => 'apple'); $tmp = array_filter(array_map('trim', $marray)); // remove blanks $str = ''; foreach ($tmp as $k=>$v) { $str .= "$k. $v "; } echo $str; //==> 1. apple, 2. orange, 5. apple
[edit] Damn! Beaten to the post.
Ah thank you after making a few changes I got it working
$marray = array( '1' => 'apple', '2' => 'orange', '3' => ' ', '4' => ' ', '5' => 'apple'); $tmp = array_filter(array_map('trim', $marray)); // remove blanks $str = ''; foreach ($tmp as $k=>$v) { $str .= "$k. $v, "; } $mrules = "Welcome Moderator please read the following rules. " . $str; ///=> Welcome Moderator please read the following rules. 1. apple, 2. orange, 5. apple,
-
Hi I'm trying to create an array to put it into a string like the following
$marray = array(
'1' => 'apple,',
'2' => 'orange,',
'3' => ' ',
'4' => ' ',
'5' => 'apple');And the string should look like
$mrules = "Welcome Moderator please read the following rules. " . 1. Apple, 2. Orange, 5. Apple.The empty values in the array shouldn't be showedany assistance please
-
Oops! typo. Remove the "pm" after "ON"
UPDATE pm
INNER JOIN Users2 u ON
pmu.mxitid = pm.ipSET pm.username = u.username
Thank you that solved the problem just learned something new with this query
-
UPDATE pm INNER JOIN Users2 u ON pm u.mxitid = pm.ip SET pm.username = u.username
I tried it
$updatename = "UPDATE pm INNER JOIN Users2 u ON pm u.mxitid = pm.ip SET pm.username = u.Username"; mysql_query($updatename) or die("Error: ".mysql_error());
getting error
-
Hi I'm trying to compare two tables with each other and update the 2nd table with the new updated name from table 1 via their unique identical ID
$resultus = mysql_query("SELECT * FROM Users2"); $rowus = mysql_fetch_array($resultus); $naamus = urldecode($rowus['Username']); $mxitus = $rowus['mxitid']; $resultnup = mysql_query("SELECT * FROM pm"); $rownup = mysql_fetch_array($resultnup); $naamup = $rownup['username']; $ipup = $rownup['ip']; while($ipup == $mxitus){ $updatename = "UPDATE pm SET username= \"$naamus\" WHERE ip = \"$mxitus\""; mysql_query($updatename) or die("Error: ".mysql_error()); }
The $mxitus and $ipup is the 2 fields that would be identical in both tables now Im trying to update the pm table username field with the naamus field from Users 2 any assistance please?
-
$read1 = "unread"; $query = "INSERT INTO pm (username,mxitid,message,time,read,ip) VALUES (\"$naam\",\"$ip1\",\"$message\",\"$date\",\"$read1\",\"$banby2\")";
I'm getting the error
This only happened when I added the read and value $read I got the field named read in my database.... any suggestion where im going wrong?
If I remove the read field the rest of the query works 100%
Never mind did some further research and found that read is a reserved word had to change it to `read`
-
$read1 = "unread"; $query = "INSERT INTO pm (username,mxitid,message,time,read,ip) VALUES (\"$naam\",\"$ip1\",\"$message\",\"$date\",\"$read1\",\"$banby2\")";
I'm getting the error
This only happened when I added the read and value $read I got the field named read in my database.... any suggestion where im going wrong?
If I remove the read field the rest of the query works 100%
-
returns array like
Array ( [0] => 800 [1] => 1280 [2] => 2 [3] => width="800" height="1280" [bits] => 8 [channels] => 3 [mime] => image/jpeg )
use the mime type instead of relying on the file extesion
I used my file Ext with this function all seems to be working fine now thank you
$imageTypeArray = array ( 0=>'UNKNOWN', 1=>'GIF', 2=>'JPEG', 3=>'PNG', 4=>'SWF', 5=>'PSD', 6=>'BMP', 7=>'TIFF_II', 8=>'TIFF_MM', 9=>'JPC', 10=>'JP2', 11=>'JPX', 12=>'JB2', 13=>'SWC', 14=>'IFF', 15=>'WBMP', 16=>'XBM', 17=>'ICO', 18=>'COUNT' ); $size = getimagesize($filename); $size[2] = $imageTypeArray[$size[2]];
My new file looks like
<?php include $_SERVER['DOCUMENT_ROOT'] . '/chat2/chat_code_header.php'; $ip = $_SERVER["HTTP_X_MXIT_USERID_R"]; if(!isset($ip)) { $ip = "Debater"; } $result9 = mysql_query("SELECT * FROM Users2 WHERE mxitid = \"$ip\""); $row = mysql_fetch_array($result9); $id = $row['ID']; // Access the $_FILES global variable for this specific file being uploaded // and create local PHP variables from the $_FILES array of information $fileName = $_FILES["uploaded_file"]["name"]; // The file name $fileTmpLoc = $_FILES["uploaded_file"]["tmp_name"]; // File in the PHP tmp folder $fileType = $_FILES["uploaded_file"]["type"]; // The type of file it is $fileSize = $_FILES["uploaded_file"]["size"]; // File size in bytes $fileErrorMsg = $_FILES["uploaded_file"]["error"]; // 0 for false... and 1 for true $fileName = preg_replace('#[^a-z.0-9]#i', '', $fileName); // filter the $filename $kaboom = explode(".", $fileName); // Split file name into an array using the dot $imageTypeArray = array ( 0=>'UNKNOWN', 1=>'GIF', 2=>'JPEG', 3=>'PNG', 4=>'SWF', 5=>'PSD', 6=>'BMP', 7=>'TIFF_II', 8=>'TIFF_MM', 9=>'JPC', 10=>'JP2', 11=>'JPX', 12=>'JB2', 13=>'SWC', 14=>'IFF', 15=>'WBMP', 16=>'XBM', 17=>'ICO', 18=>'COUNT' ); $size = getimagesize($fileTmpLoc); $size[2] = $imageTypeArray[$size[2]]; $fileExt = $size[2]; // Now target the last array element to get the file extension // START PHP Image Upload Error Handling -------------------------------- if (!$fileTmpLoc) { // if file not chosen echo "ERROR: Please browse for a file before clicking the upload button."; exit(); } else if($fileSize > 5242880) { // if file size is larger than 5 Megabytes echo "ERROR: Your file was larger than 5 Megabytes in size."; unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder exit(); } else if (!preg_match("/.(gif|jpg|png)$/i", $fileName) ) { // This condition is only if you wish to allow uploading of specific file types echo "ERROR: Your image was not .gif, .jpg, or .png."; unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder exit(); } else if ($fileErrorMsg == 1) { // if file upload error key is equal to 1 echo "ERROR: An error occured while processing the file. Try again."; exit(); } // END PHP Image Upload Error Handling ---------------------------------- // Place it into your "uploads" folder mow using the move_uploaded_file() function $moveResult = move_uploaded_file($fileTmpLoc, "images/".$id.".".$fileExt); // Check to make sure the move result is true before continuing if ($moveResult != true) { echo "ERROR: File not uploaded. Try again."; exit(); } // Include the file that houses all of our custom image functions include_once("ak_php_img_lib_1.0.php"); // ---------- Start Universal Image Resizing Function -------- $target_file = "images/".$id.".".$fileExt; $resized_file = "images/resized_".$id.".".$fileExt; $wmax = 320; $hmax = 240; ak_img_resize($target_file, $resized_file, $wmax, $hmax, $fileExt); unlink($target_file); // ----------- End Universal Image Resizing Function ---------- // ---------- Start Convert to JPG Function -------- if (strtolower($fileExt) != "jpg") { $target_file = "images/resized_".$id.".".$fileExt; $new_jpg = "images/resized_".$id.".jpg"; ak_img_convert_to_jpg($target_file, $new_jpg, $fileExt); unlink($target_file); } $new_jpg = "images/resized_".$id.".jpg"; if(!get_magic_quotes_gpc()) { $new_jpg = addslashes($new_jpg); $filePath = addslashes($filePath); } $result = mysql_query("UPDATE Users2 SET pprofilepic='$new_jpg', aprove='requested' WHERE mxitid='$ip'") or die(mysql_error()); // ----------- End Convert to JPG Function ----------- // Display things to the page so you can see what is happening for testing purposes echo "The file named <strong>$fileName</strong> uploaded successfuly.<br /><br />"; echo "It is <strong>$fileSize</strong> bytes in size.<br /><br />"; echo "It is an <strong>$fileType</strong> type of file.<br /><br />"; echo "The file extension is <strong>$fileExt</strong><br /><br />"; echo "The Error Message output for this upload is: $fileErrorMsg"; if($result){ header('Location: ../profile/thankyou.php'); } else { echo "ERROR"; } // close mysql mysql_close(); ?>
-
Try processing it as if it were a jpeg file. That worked for me after downloading
Isn't there a way to change the file type to the right one before processing it? because doing it manually is a pain?
-
undefined function json_last_error()
in PHP Coding Help
Posted
Hi, I im using an API script to retrieve info, but im getting the error
Can anyone please help me out what could be the cause of this error and how to resolve it?