Jump to content

bayswater

Members
  • Posts

    19
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

bayswater's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi Russ, Once again - thank you very much for your assistance. I'm trying to build a library of screencasts and adding/editing the roles of the individual screencasts are working fine thanks to your script. But I can't seem to get it working in the list that shows me all my screencasts, like: - screencast name 1 (only for "teachers", "students") - screencast name 2 (only for "Secretaries") - screencast name 3 - screencast name 4 (only for "teachers", "Secretaries") Can you spot how to include - some of - your code to my sql? This includes some categories and the different tools, the screencasts are made for. // SHOW ALL RECORDS ACCORDING TO LANGUAGE (NOT A SEARCH) $sql_screencasts = "SELECT t.tool_id, t.tool_name, c.cat_id, c.cat_name_".$lang.", s.sc_id, s.sc_desc_".$lang.", s.sc_name, sc_stats FROM elsa_sc_tools t JOIN elsa_sc_categories c ON c.cat_rel_to_tool = t.tool_id JOIN elsa_sc_screencasts s ON s.sc_rel_to_cat = c.cat_id ORDER BY t.tool_name asc,c.cat_name_".$lang." asc,s.sc_desc_".$lang." asc"; $searching = "false"; $result = mysql_query($sql_screencasts); $count_rows = mysql_num_rows($result);
  2. Just out of curiosity - and I guess it would be nice to actually understand this instead of merely copying a code - your first suggestion - with the two selects, how would that look. Below is my actual SQL (I used the article example in my first post because it was easier to explain). Do you make 2 $sql_roles = mysql_query(" ? Because it would need variables from both in the latter while? <?php $sql_roles = mysql_query("SELECT a.role_id As role_id, a.role_name_dk As role_name_dk, a.role_name_en As role_name_en, b.context_sc_id As context_sc_id, IF(b.context_id,1,0) As selected FROM elsa_sc_roles a LEFT JOIN elsa_sc_context b ON (b.context_role_id = a.role_id AND b.context_sc_id = '".$edit_sc_id."') ORDER BY a.role_name_dk asc"); while ($row_roles = mysql_fetch_array($sql_roles)) { $role_id = $row_roles['role_id']; $role_name_dk = $row_roles['role_name_dk']; $role_name_en = $row_roles['role_name_en']; $context_sc_id = $row_roles['context_sc_id']; ?> <input type="checkbox" name="sc_context[]" id="sc_context" value="<?php echo $role_id; ?>" <?php if ($edit_sc_id == $context_sc_id) echo "checked"; ?>> <?php echo $role_name_dk; ?> <span class='faded'>(En: <?php echo $role_name_en; ?>)</span><br> <?php } ?>
  3. Thanks Russell, I'm going with your last suggestion I'm afraid. It's a small site, not many users etc. and it works beautifully. Thank you very much!
  4. Hi, I have a list of articles, for which it is supposed to be noted if an article is relevant for only a certain user group. I have three tables: 1. articles: article_id (autonum) | article_name 2. userroles: role_id (autonum) | role_name 3. context: context_id (autonum) | context_article_id | context_role_id As an example the article "PHP for beginners" (with article_id 3) is relevant for the user group "Students" (role_id 4) and "Teachers" (role_id 5) but NOT relevant for "Secretaries" (role_id 7) In the database: 1. articles: 3 | PHP for beginners 2. userroles: 4 | Students 5 | Teachers 7 | Secretaries 3. context: (here is context_id set to 12 og 13 as an example) 12 | 3 | 4 13 | 3 | 5 My problem is that when editing a article - for example to change the relevant user groups I can't get the SQL to work. It should list ALL the exisisting user roles to chose from, and mark the ones (in a check box) that are selected for the specific/chosen article. My attempt: $sql_roles = mysql_query("SELECT DISTINCT r.role_id, r.role_name, c.context_id, c.context_article_id, c.context_role_id, a.article_id FROM (userroles r LEFT JOIN context c ON c.context_role_id = r.role_id) LEFT JOIN articles a ON a.article_id = c.context_sc_id ORDER BY r.role_name asc"); But this lists some roles that are used by another article more than once (role_id in ()): PICKED (5) Teachers (5) Teachers (7) Secretaries ( Super Users (4) Students PICKED (4) Students How should my SQL look to accomplish this?
  5. Hmmm maybe I got it: I add: $first_cat = 'true'; before the while (next to your empty variables) Then: if($tmp_cat != $cat_id){ echo "".(($first_cat != 'true') ? "</div>":"")."<div class='category'>".$cat_name_dk."</div><div class='screencasts'>"; $tmp_cat = $cat_id; //update tmp variable $first_cat = "false"; } And finally: echo "</div>"; // CLOSE DIV AFTER LAST <div class='screencasts'> - outside the WHILE end Would you agree?
  6. Hi Denno, One follow-up question - if you're still about: If I want a div tag around ALL the: if($tmp_sc != $sc_desc_dk){ echo "<br>- - <a href='view.php?id=".$sc_id."'>".$sc_desc_dk."</a><br>"; $tmp_sc = $sc_desc_dk; //update tmp variable } How would I do that? Right now I get: <div> - - something 1</div> <div> - - something 2</div> <div> - - something 3</div> and all I need is: <div> - - something 1 - - something 2 - - something 3 </div>
  7. Thanks Denno, I used your approach but used CSS instead - it now looks exactly like I want it to. Thanks again!
  8. Hi, In my database I have tables for: - Tools (sc_tools) - Categories (sc_categories) - Screencasts (sc_screencasts) In the database there are connections between the mentioned as follows: 1) "sc_tools" has an id: tool_id 2) "sc_categories" has an id: (cat_id) AND a relation to sc_tools (cat_rel_to_tool - which is = tool_id) 3) "sc_screencasts" has an: id (sc_id) AND a relation to sc_tools (sc_rel_to_tool - which is = tool_id) AND a relation to sc_categories (sc_rel_to_cat - which is = sc_id) Ok, so I want to list my data as follows: Tool 1 - Category 1 - - Screencast 1.1 - - Screencast 1.2 - Category 2 - - Screencast 2.1 Tool 2 - Category 1 - - Screencast 1.1 osv. I have been tryin with the JOIN-query: $sql_screencasts = mysql_query("SELECT t.tool_id, t.tool_name, c.cat_id, c.cat_name_dk, s.sc_id, s.sc_desc_dk FROM sc_tools t JOIN sc_categories c ON c.cat_rel_to_tool = t.tool_id JOIN sc_screencasts s ON s.sc_rel_to_cat = c.cat_id "); while ($row_screencasts = mysql_fetch_array($sql_screencasts )) { $tool_name = $row_screencasts["tool_name"]; $cat_name_dk = $row_screencasts["cat_name_dk"]; $sc_desc_dk = $row_screencasts["sc_desc_dk"]; $sc_id = $row_screencasts["sc_id"]; echo "<br><font size=3><b>".$tool_name."</b></font><br>"; echo "- ".$cat_name_dk; echo "<br>- - <a href='view.php?id=".$sc_id."'>".$sc_desc_dk."</a><br>"; } But is lists the data as: Tool 1 - Category 1 - - Screencast 1 Tool 1 - Category 1 - - Screencast 2 etc. - I can't get e GROUP BY working either, so I'm lost right now. Hopefully an expert can help me out? Any help is highly appreciated!
  9. Hi, Ok, so I'm making a registration form system, where I can create new registration forms for the users to pick a date etc. In my form I can add and remove text fields via Javascript - to add additional dates etc. so I don't know if I'll be submitting 3 fields or 15. The could look like this: <input type="hidden" name="session_id[]" value="<?php echo $session_id; ?>"> <input type="text" name="picked_date[]"> <input type="text" name="picked_room[]"> They are put in a big array: De bliver smidt i et stort array: $n=0; foreach ($session_id as $_session_id) { $bigar[$n][1] = $_session_id; $n++; } $n=0; foreach ($picked_date as $_picked_date) { $bigar[$n][2] = $_picked_date; $n++; } $n=0; foreach ($picked_room as $_picked_room) { $bigar[$n][3] = $_picked_room; $n++; } $n=0; which is then updated in the database using: foreach ($bigar as $part) { mysql_query("UPDATE... } Right - so far so good. The updating works fine with existing fields, but if I remove some of the fields (via JS) it obviously only updates the remaining in the array. The left out will be ignored. On the same note I would like to add fields as well, so - the bottom line - I want to: - UPDATE rows, where the ID is in the array - DELETE existing rows, WHERE the ID is NOT in the array - CREATE new rows for the new fields in the array (not having an ID) How can this be achieved? Hope someone can help...
  10. Ah, yes, I get the category !=0, but I now realize that I pasted the wrong SQL I have 2 almost identical and in this second - I NEED a join (I guess?) to the categories table: mysql_query("UPDATE ".$prefix."course c INNER JOIN ".$prefix."course_categories cat ON c.category = cat.id SET c.visible = '1' WHERE cat.path like '%/".$vist."/%' AND c.visible = '0' AND c.category <> '0'");
  11. Hi experts, I have this update, which DOESN'T work when my page hooks up to a postgres database: pg_query("UPDATE ".$prefix."course c INNER JOIN ".$prefix."course_categories cat ON c.category = cat.id SET c.visible = '1' WHERE c.category = '".$vist."' AND c.visible = '0' AND c.category <> '0'"); Is there a conflict with the JOIN in an update when it comes to postgres, or...? My identical code for Mysql is working fine: mysql_query("UPDATE ".$prefix."course c INNER JOIN ".$prefix."course_categories cat ON c.category = cat.id SET c.visible = '1' WHERE c.category = '".$vist."' AND c.visible = '0' AND c.category <> '0'");
  12. Hi, I am trying to make a registration form for users. The registration is for a seminar introducing a particular system for them. This (web based) system is merely a remote website. But in order for the users to actually use the system at the seminar, they HAVE to have logged in on the system in advance/prior to the seminar at least once. So in my registration form I want to include a curl login of the system, which should be invisible to the users. Hence I don't want to open a popup loading the system/remote site - I would like for this to happen without the users knowing it. So they enter username and password, Curl then does the login and then returns either "Succes! You were logge in!" or "There was an error. You were not logged in!". I have no use for additional information from the remote site - the only thing is that they should login this once - that's it. My code is below - and it works if the remote site is NOT using https (that is http ;-)) but if the remote site IS running https I get no message back. The line "if (stristr($result, "loginerrors"))" is set because the remote site includes the keyword "loginerrors" if you weren't logged in properly. Any suggestions? <?php $post_data['username'] = 'something@domain.com'; $post_data['password'] = 'MyPassword'; //traverse array and prepare data for posting (key1=value1) foreach ( $post_data as $key => $value) { $post_items[] = $key . '=' . $value; } //create the final string to be posted using implode() $post_string = implode ('&', $post_items); //create cURL connection $curl_connection = curl_init('https://www.domain.com/login.php'); //set options curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false); //set data to be posted curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string); //perform our request $result = curl_exec($curl_connection); if (stristr($result, "loginerrors")) { echo "There was an error. You were not logged in!"; }else{ echo "Succes! You were logge in!"; } //close the connection curl_close($curl_connection); ?>
  13. Geez, it was merely the databaseconnection - it works beautifully now. Thanks for your input!
  14. Hi, some guy sent me the code below - and I think we're almost there, but I'm unclear about the statement: /* query here, lets say that your link id is under $link */ If I just copy the code it says "Undefined variable: link" - which I can understand, so what to do with "$link"? <?php $sql="SELECT id, path, name FROM ".$prefix."course_categories WHERE visible = '1' ORDER BY path ASC"; /* query here, lets say that your link id is under $link */ while($var = mysql_fetch_array($result)) { $path = explode("/", $var["path"]); $temp = array_pop($path); //pop the last one as it will always be the deepest subcategory echo "<option value=\"".$var["id"]."\">"; foreach($path as $ids) { $nextsql = "SELECT name FROM ".$prefix."course_categories WHERE id = '$ids'"; $name = mysql_fetch_array(mysql_query($nextsql, $link)); echo $name["name"].'/'; } echo $var["name"]."</option>"; } ?>
  15. Hi, yes, I can try :-) Just for starters - my SQL is this: $sql="SELECT id, name, parent, path, sortorder FROM ".$prefix."course_categories WHERE visible = '1' ORDER BY path asc"; My current select-option code looks like this: <option value="<?php echo $row['id']; ?>"><?php echo $row['name']; ?></option> That gives me this list: 1.semester Underkategori_1_i_1.semester 3.semester Underkategori_1_i_3.semester Underkategori_1.1_i_3.semester Underkategori_2_i_3.semester 5.semester But I would like for it to show the path (the relation between category and under-/subcategory (see "parent" and "path" in the database (screenshot above)), so that is will display the list like this - INCLUDING the names of parent categories: 1.semester 1.semester/Underkategori_1_i_1.semester 3.semester 3.semester/Underkategori_1_i_3.semester 3.semester/Underkategori_1_i_3.semester/Underkategori_1.1_i_3.semester 3.semester/Underkategori_2_i_3.semester 5.semester If I add $row['path']; to the select-option code: <option value="<?php echo $row['id']; ?>"><?php echo $row['path']; ?>/<?php echo $row['name']; ?></option> It gives me this: /2/1.semester /2/7/Underkategori_1_i_1.semester /3/3.semester /3/4/Underkategori_1_i_3.semester /3/4/6/Underkategori_1.1_i_3.semester /3/8/Underkategori_2_i_3.semester /5/5.semester But I want the names instead of the id's.
×
×
  • 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.