Jump to content

learningprobs

Members
  • Posts

    14
  • Joined

  • Last visited

learningprobs's Achievements

Member

Member (2/5)

0

Reputation

  1. Ok, it seems that this works fine: UPDATE delivery_addresses SET primary_address = IF(address_id=5, 1, 0) WHERE user_id = 179 Could anyone confirm please that this is the right way to set 1 field to 1 while changing all the others to zero? Will this not cause a big load on the server when more and more rows are added? Thanks,
  2. Hello, I would like a little bit of guidance please to make sure I am not going to code something bad and have to redo it down the line. I have these fields: TAble = delivery_addresses FIELDS = user_id, company, name, surname, street, town_id, postcode, countries_id, primary Each user has multiple delivery addresses but only 1 can be set as a primary = 1 at any one time. My problem is how to set only 1 field to 1 but have all the others back to 0 per user. With a bit of research I have this command(user = id of 170) UPDATE delivery_addresses SET primary=IF(id=170, 1, 0) From what I understood is that "if the user with the id of 170 is found, set the primary column to 1 and all the others to 0". Am I correct to assume this? Now if I wish to INSERT an address and set it as primary from the start, this will then require 2 queries, one insert that sets the primary to 0 and 1 to update it back to 1, is this the right way of doing it? Thank you in advance.
  3. Hi Jacques, yes sorry, i will add the ? and bind parameters to the query, I did not even notice i forgot it. Regarding the arrays, thanks. i have no idea why, since I started php, I have always struggled with arrays....I need to find a good course on this. From what I understand, an object would be like the title of a group of information. But also can an object be inside another object or is it called something else? Thanks.
  4. Thanks Jacques, strange I am not receiving notifications when I get replies. I clicked on "notify" when there is an answer. I am wondering if the forum system is down. Thanks for your help.
  5. Hello, I would like to output one by one all the values inside an array randomly but never output again the ones that have already been output until all the numbers in that array have been output. At the moment my array output numbers like this: Array ( [0] => Array ( [number1] => 1 [number2] => 4 ) [1] => Array ( [number1] => 1 [number2] => 3 ) [2] => Array ( [number1] => 1 [number2] => 2 ) ) So I would like the keys 0,1,2 to output randomly 1 time each and never have them to output again until all 3 keys have been output. In short, I will use the number1 and number2 separately and add "+" in between. I just want the system to show his additions as explained above so he learns them faster but not in order. Thanks in advance for your help.
  6. Hello, I am having a little problem. I have created this code here: $mysqlsearch = implode(',',$additions_result); $res = array(); $stmt = $conn->prepare("SELECT number1,number2 FROM table_2_numbers WHERE number1 IN($mysqlsearch)"); $stmt->bind_result($number1, $number2); $stmt->execute(); $stmt->store_result(); if($stmt->num_rows() > 0){ while ($stmt->fetch()) { $res[] = array ('number1' => $number1, 'number2' => $number2); }} $stmt->free_result(); $stmt->close(); All my values are going correctly in the table, if I print_r($res), I get this: Array ( [0] => Array ( [number1] => 1 [number2] => 4 ) [1] => Array ( [number1] => 1 [number2] => 3 ) [2] => Array ( [number1] => 1 [number2] => 2 ) [3] => Array ( [number1] => 1 [number2] => 1 ) [4] => Array ( [number1] => 1 [number2] => 0 ) [5] => Array ( [number1] => 1 [number2] => 5 ) [6] => Array ( [number1] => 1 [number2] => 6 ) [7] => Array ( [number1] => 1 [number2] => 7 ) [8] => Array ( [number1] => 1 [number2] => 8 ) [9] => Array ( [number1] => 1 [number2] => 9 ) [10] => Array ( [number1] => 2 [number2] => 0 ) [11] => Array ( [number1] => 2 [number2] => 1 ) [12] => Array ( [number1] => 2 [number2] => 2 ) [13] => Array ( [number1] => 2 [number2] => 3 ) [14] => Array ( [number1] => 2 [number2] => 4 ) [15] => Array ( [number1] => 2 [number2] => 5 ) [16] => Array ( [number1] => 2 [number2] => 6 ) [17] => Array ( [number1] => 2 [number2] => 7 ) [18] => Array ( [number1] => 2 [number2] => 8 ) [19] => Array ( [number1] => 2 [number2] => 9 ) [20] => Array ( [number1] => 3 [number2] => 0 ) [21] => Array ( [number1] => 3 [number2] => 1 ) [22] => Array ( [number1] => 3 [number2] => 2 ) [23] => Array ( [number1] => 3 [number2] => 3 ) [24] => Array ( [number1] => 3 [number2] => 4 ) [25] => Array ( [number1] => 3 [number2] => 5 ) [26] => Array ( [number1] => 3 [number2] => 6 ) [27] => Array ( [number1] => 3 [number2] => 7 ) [28] => Array ( [number1] => 3 [number2] => 8 ) [29] => Array ( [number1] => 3 [number2] => 9 ) ) I was expecting to choose for example "Array ( [number1] => 1 [number2] => 4 )" by doing this: echo $res[0]->number1; echo $res[0]->number2; But when doing this I am not getting any output. What am I doing wrong please? Thank you in advance for your help.
  7. you are a master ginerjm...........!!!!!!!!!!!!!! You just asked me this question "Can we see the actual file being brought in? " then I thought...." Oh no!!!!!!!". Well you are right, the problem is from the other end, it is the files themselves having a PHP error in them. Well done, I have been turning around in circle for a solution in another forum, noone asked this question when in fact it was the most logical thinking.
  8. Sorry Max this is my latest code, it is driving me nuts, I have been on it for hours. People in another forum are saying that my database connection might be the problem but it does not make sense, why would I get the echo to work on that variable $video_categories_id and not on the require statement? I only get the stmt error via the require and not the echo(using both the same variable) PHP Code: <?php $video_activated = 1; $stmt = $conn->prepare("SELECT video_categories_id FROM video_categories ORDER BY video_categories_id, video_activated = ?"); $stmt->bind_param('i', $video_activated); $stmt->bind_result($video_categories_id); $stmt->execute(); $stmt->store_result(); if($stmt->num_rows() > 0){ while($stmt->fetch()) { require 'resources/templates/frontend/video_category_' . $video_categories_id . '.php'; }} $stmt->free_result(); $stmt->close(); ?> If I change PHP Code: require 'resources/templates/frontend/video_category_' . $video_categories_id . '.php'; to PHP Code: echo 'resources/templates/frontend/video_category_' . $video_categories_id . '.php'; I get everything fine: resources/templates/frontend/video_category_1.php resources/templates/frontend/video_category_2.php resources/templates/frontend/video_category_3.php resources/templates/frontend/video_category_4.php resources/templates/frontend/video_category_5.php resources/templates/frontend/video_category_6.php resources/templates/frontend/video_category_7.php resources/templates/frontend/video_category_8.php resources/templates/frontend/video_category_9.php resources/templates/frontend/video_category_10.php resources/templates/frontend/video_category_11.php resources/templates/frontend/video_category_12.php I then pasted the path into my url: website.com/resources/templates/frontend/video_category_12.php I could see the output, therefore my path is fine. There is something(no idea if it is because of the prepared statements) that do not let that "require" pass through in my fetch() Anything else works but not when I add "require" in my while($stmt->fetch()) {}
  9. Hello, Today for the first time I tried to use include() inside a while loop, to my surprise, it does not work. The error message I am receiving is: Warning: mysqli_stmt::fetch(): Couldn't fetch mysqli_stmt in /home/xxx/public_html/index.php on line 31 Warning: mysqli_stmt::free_result(): Couldn't fetch mysqli_stmt in /home/xxx/public_html/index.php on line 51 Warning: mysqli_stmt::close(): Couldn't fetch mysqli_stmt in /home/xxx/public_html/index.php on line 52 Here is my code: <?php $video_activated = 1; $stmt = $conn->prepare("SELECT video_categories_id FROM video_categories ORDER BY video_categories_id, video_activated = ?"); $stmt->bind_param('i', $video_activated); $stmt->bind_result($video_categories_id); $stmt->execute(); $stmt->store_result(); if($stmt->num_rows() > 0){ while($stmt->fetch()) { if($video_categories_id == 1){ include(TEMPLATE_FRONT . DS . "video_category_1.php"); } if($video_categories_id == 2){ include(TEMPLATE_FRONT . DS . "video_category_2.php"); } if($video_categories_id == 3){ include(TEMPLATE_FRONT . DS . "video_category_3.php"); } if($video_categories_id == 4){ include(TEMPLATE_FRONT . DS . "video_category_4.php"); } }} $stmt->free_result(); $stmt->close(); ?> All I am trying to do is load my gallery pictures according to the database categories status being either activated or not. Any idea why Include does not work in this case please? If I replace the include() by echo, it works. Thanks.
  10. Hello, I am having a bit of an annoying problem. I am trying to get an error message returned as json from my php script, at the moment all I am getting is this error in the console: parsererror SyntaxError: Unexpected token < in JSON at position 10(…) I would have believed(based on what I researched) that this error was due to the dataType not being set properly, but it is. Here is page 1 ajax code: var video_title_php = document.getElementById('videoName').value; var video_description_php = document.getElementById('videoDescription').value; var video_category_php = document.getElementById('videoCategoryId').value; var video_uid = "<?php echo $id; ?>"; $.ajax({ url: 'index.php?page=producer_save_video.php', dataType: "json", data: { videoidurl:videoId, video_title:video_title_php, video_description:video_description_php, video_category:video_category_php, video_uid:video_uid }, type: 'POST', success: function (response) { $("#php_results").html(response); }, error: function(jqXHR, textStatus, errorThrown) { console.log(textStatus, errorThrown); } }) And this is the simple json text I am trying to output on the other page: <?phpecho json_encode(array('error' => 'Well done! Your video has been uploaded!')); ?> Any idea please? Thanks.
  11. Thanks for sharing this beautiful tool I was not aware of :-) it looks like the problem is actually from the id I am inputting, I thought the "page number" was the id of the user profile but when I try to input this number in the field I am getting the same error... This is weird, no idea what they refer as "page" as I have also tried a video page and it says "error 500".
  12. Hello, This is the first API I am trying to work with and would like to know if you could guide me a little bit please. I am trying to parse a url as it shows here: https://developer.vimeo.com/api/upload/videos As you can see, the format is: GEThttps://api.vimeo.com/me And it should return something like: "upload_quota":{ "space":{ "free":53525865655, "max":53687091200, "used":161225545 }, "quota":{ "hd":true, "sd":true } }, I took a random user on Vimeo as an example and tried to output the data based his account data but no luck: <?php $api_request_url = 'https://api.vimeo.com/user1577007'; curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json')); curl_setopt($ch, CURLOPT_URL, $api_request_url); curl_setopt($ch, CURLOPT_HEADER, TRUE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE); $api_response = curl_exec($ch); $api_response_info = curl_getinfo($ch); curl_close($ch); // Response HTTP Status Code echo $api_response_info['upload_quota']; ?> Any idea what am I actually doing wrong please? Thank you.
  13. Hello, I am having a little problem, nothing serious but it is annoying. I have made a CRUD, this page is for my update page, the form values are loaded from mysql, but when there is a POST error, the form may also refresh. I have managed to get my values to load ok and refresh ok, the only problem is that I am getting double values in my dropdown menu(1 from the $_POST and 1 from the database). How to remedy to this please? Here is my prepared statement: <?php if(isset($_GET['id'])){ $id = (int)$_GET['id']; $stmt = $conn->prepare("SELECT u.users_id, u.users_firstname, u.users_lastname, u.users_username, u.users_email, u.users_password, u.users_active, u.users_phone, u.users_countries_id, u.users_role, r.role_name, c.countries_name, a.activated_id, a.activated_name FROM users AS u LEFT JOIN roles AS r ON u.users_role = r.role_id LEFT JOIN countries AS c ON u.users_countries_id = c.countries_id LEFT JOIN activated AS a ON u.users_active = a.activated_id WHERE u.users_id = ?"); $stmt->bind_param('i', $id); $stmt->bind_result( $users_id, $users_firstname, $users_lastname, $users_username, $users_email, $users_password, $users_active, $users_phone, $users_countries_id, $users_role, $role_name, $countries_name, $activated_id, $activated_name); $stmt->execute(); $stmt->store_result(); $stmt->fetch(); $stmt->free_result(); $stmt->close(); } ?> And here one of my dropdown menus: <div class="form-group"> <label for="activated">Activated?</label> <select class="form-control" name="active"> <option value="<?php echo (int)$activated_id; ?>"> <?php echo htmlentities($activated_name); ?> </option> <?php $stmt = $conn->prepare("SELECT activated_id,activated_name FROM activated"); $stmt->bind_result($activated_id,$activated_name); $stmt->execute(); $stmt->store_result(); if($stmt->num_rows() > 0){ while ($stmt->fetch()) { $s = ""; if(isset($_POST['active']) && ($_POST['active'] == $activated_id)) { $s = " selected"; } echo "<option value='".(int)$activated_id."'".$s.">".htmlentities($activated_name)."</option>"; } } $stmt->free_result(); $stmt->close(); ?> </select> </div> Here is what happens: http://screencast.com/t/newQksedwkQ Thank you!
×
×
  • 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.