minitauros 151 Junior Poster Featured Poster

"x equals x" is written with 2 times an "=", not one time ;). You are now setting a new value for $n in each if() statement. You should write it as $n == 3 instead of $n = 3.

Also you're not comparing your results correctly. In line 2 of the script you present, you set $n to be a result set, not the actual result. The actual result would be $n['alias_switch'].

Try this code, if you wish:

<?php
$result = mysql_query("SELECT alias_switch FROM peoplebase");
$n = mysql_fetch_assoc($result);
$alias_switch = $n['alias_switch'];

if($alias_switch == "1") {
    mysql_query("UPDATE peoplebase SET alias_switch='2'");
}
elseif($alias_switch == "2") {
    mysql_query("UPDATE peoplebase SET alias_switch='3'");
}
elseif($alias_switch == "3") {
    mysql_query("UPDATE peoplebase SET alias_switch='1'");
}
RaeesIqbal commented: Thank you,,,, I am such a dumb ass, cant believe i was on this problem from last 1 hour. I'm so happy that i want to kiss your forehead. Thank you +0
minitauros 151 Junior Poster Featured Poster

Yea so dont use the window.resize() jQuery function then, but just check the viewport width while the page is being loaded :). And you're welcome!

minitauros 151 Junior Poster Featured Poster

Well does "making it look like it is in a subfolder" not equal "virtually putting it in a subfolder"? ;) This is the only option I know about that works, but I'm curious as to what others think of this.

minitauros 151 Junior Poster Featured Poster

Try using absolute paths to your css files. E.g. not css/stylesheet.css, but /css/stylesheet.css or http://www.yourwebsite.com/css/stylesheet.css

minitauros 151 Junior Poster Featured Poster

I cannot say with 100% certainty that it works on every browser, but I wouldn't see why it wouldn't :). So yeah, I would consider it safe to use if I were to make a website with a smaller viewport.

minitauros 151 Junior Poster Featured Poster

Hmmm well I have no better idea then than to write all your functions to an external file each time the list of categories gets changed, and then including that file in each file that you need to use those functions in.

You can write to a file using file_put_contents(), for example. What I'm saying is: generate those functios as you would write them in a new PHP file, and then actually write them to a new (or existing) PHP file.

If anyone has any better ideas, I'd love to hear them. If noone is taking the trouble to read such a long post and my answer is not what you are looking for, I would suggest starting a new topic with the same question :). Hope I could be of help anyway!

minitauros 151 Junior Poster Featured Poster

Yea I may not have used the same variable names as you have. You might want to check the code I provided and change the variable names to whatever variable names you want to use.

minitauros 151 Junior Poster Featured Poster

Oh that looks like a typo ^^. Have you checked out what's on line 156? It says an invalid argument is supplied for the foreach() loop, which is correct, cause we're passing $search_term to it instead of $search_terms (with an "s" at the end). If you correct that, I think it should work :).

minitauros 151 Junior Poster Featured Poster

Ouch, that sounds like the file has not yet finished uploading? :) Or is there something wrong on line 327?

minitauros 151 Junior Poster Featured Poster

I did the following, and that worked. Is that any help or am I still not understanding your problem correctly?

<?php
$function_content = '
    if($arg1 == \'test\')
    {
        echo \'Yes\';
    }
    else
    {
        echo \'No\';
    }
    ';

$function = create_function('$arg1', $function_content);

$function('test'); // Returned "Yes".
$function('testt'); // Returned "No".
minitauros 151 Junior Poster Featured Poster

Ah now we're going somehwere. You could try the following code. If anything is unclear to you, let me know :).

<?php
$search_terms = $_REQUEST['q'];

// Make sure we can do a safe input by applying mysql_real_escape_string.
// Check out the PHP documentation if you want to learn more about array_map().
$search_terms = array_map('mysql_real_escape_string', $search_terms);

if($search_terms)
{
    foreach($search_term as $term)
    {
        // Let's build the WHERE part of the query.

        $where_parts .= '(';
        $where_parts .= ' keywords LIKE "%' . $term . '%" ';
        $where_parts .= ' OR catagories LIKE "%' . $term . '%" '; // For your info, it's "categories", not "catagories" ^^.
        $where_parts .= ' title LIKE "%' . $term . '%" ';
        $where_parts .= ')';
    }

    // Let's implode the where parts to create an actual where clause.
    $where = implode(' OR ', $where_parts); // Change to AND if you want, of course :).

    // Your possible new query could be as follows:
    $q = 'SELECT title, 
            id, 
            keywords, 
            catagories, 
            emurl 
        FROM libvid
        WHERE ' . $where . '
        ORDER BY title DESC';
}
else
{
    //* No search was done.
}
minitauros 151 Junior Poster Featured Poster

Ah I see three queries there, am I right? And does each of those queries return ALL rows from the table specified? Because there seems to be nothing wrong with your queries, although I've personally never seen "IS NOT null" being used at the end of a WHERE statement, but I cannot say with certainty that that is incorrect syntax. You could try and see what happens if you don't add that to the end of your WHERE statement.

If I were you, I wouldn't use so many separate queries. Instead, I would slightly modify my WHERE part to include all the WHERE...LIKE... parts. For example WHERE (... LIKE first word) OR (... LIKE second word) OR (... LIKE third word) etc. Is that clear enough? :)

minitauros 151 Junior Poster Featured Poster

Have you checked out the create_function() function? See here: http://php.net/manual/en/function.create-function.php

minitauros 151 Junior Poster Featured Poster

Well, if you want to search for a match with multiple words, you should probably use WHERE ... LIKE %...% OR ... LIKE %...% (for example).

So, in your example:

WHERE (keywords LIKE '%$word1%' OR catagories LIKE '%$word1%' OR title LIKE '%$word1%')
OR (keywords LIKE '%$word2%' OR catagories LIKE '%$word2%' OR title LIKE '%$word2%')

etc.

To remove the comma's, simply pass an empty parameter to your implode function :). E.g. implode('', $array).

If you need more info, could you please post the exact query that you are using to search for results? So not your code, but the actual query itself, echo'd? :)

minitauros 151 Junior Poster Featured Poster

So exactly what is wrong with your $var at the current moment? Are there comma's where you don't want them? Or are there values that you do not want to be included in $var?

minitauros 151 Junior Poster Featured Poster

Also, for the error function, add a parameter (data) to it so that you can see what error is coming back.

What stbuchok says :). Usually when I get an error it's because the specified file cannot be found. Javascript does not always use the same working directory as PHP, so make sure you specify the exact location to the file you want to load from the page you want to load it from. E.g. if you're making an AJAX call from index.php, and the file you're requesting is in a folder, you should include the folders in your "url" parameter.

minitauros 151 Junior Poster Featured Poster

Damn that is a whole lot of code man. Would you be so kind to specify the lines that you would like us to look at? ^^

By the way, on a side note, using $_REQUEST is considered unsafe/risky, as it may get defined by $_COOKIE, $_GET and $_POST values, which means it leaves room for malicious injections and stuff plus you might end up using the wrong data (if you have the same key in a $_GET, $_POST and $_COOKIE).

minitauros 151 Junior Poster Featured Poster

What you can do on the fly is $('head').append('<meta name="bla" content="test">'); :). If you don't put that in a $(document).ready(), then it will be executed while the page is being generated. E.g. if you put it between your <head> and </head> tags, the <meta> tag is created before your browser even parses the </head> tag, for as far as my knowledge goes.

minitauros 151 Junior Poster Featured Poster

Also, check out CSS3 media queries (Google it). They're probably perfect for your situation!

minitauros 151 Junior Poster Featured Poster

Yes it does, when it resizes the <meta> tags are added, but I'm not sure how dynamically added <meta> tags work for search engine spiders etc.

minitauros 151 Junior Poster Featured Poster

Your code should work, as you have a redirect in logout.php, which means that if you were to press backspace after you've been redirected, you would end up in logout.php again, which would redirect you to index.php :o.

minitauros 151 Junior Poster Featured Poster

Well I guess that would be possible :). Maybe something like:

$(window).resize(function()
{
    // Do your width checks etc. here, check out the jQuery website for more info.

    if(page_width < 700)
    {
        // Create <meta> tag.
        $('head').append('<meta name="bla" content="test">');
    }
    else
    {
        // Remove the <meta> tag.
        $('meta[name="bla"]').remove();
    }
});
minitauros 151 Junior Poster Featured Poster

So then you have the option to either load the subcategories while loading the page and then hide them, and show them when the user hovers over a category, OR to fetch them using an AJAX call.

Using the first option you would put your categories in a <div>, and your subcategories inside a <div> within that <div>. Give the category <div>s a recognizable class, e.g. <div class="category">, and the subcategory <div>s as well, e.g. <div class="subcategory">.

Then you include the following Javascript code on your page (assuming you're using jQuery):

$(document).ready(function()
{
    $('div.category').hover(function()
    {
        //* What happens when the user hovers over the target?

        // Show the subcategories.
        $(this).find('div.subcategories').show();
    },
    function()
    {
        //* What happens when the user's mouse leaves the target?

        // Hide the subcategories.
        $(this).find('div.subcategories').hide();
    });
});

If you want to load your subcategories using AJAX, you'd have to create a separate PHP file that retrieves only the subcategories for the category with the given ID. Then you'd use the following Javascript code (using the same setup as before):

$(document).ready(function()
{
    $('div.category').hover(function()
    {
        //* What happens when the user hovers over the target?

        // Do we need to load subcategories?
        if($(this).find('div.subcategories').html() == '')
        {
            //* The subcategories <div> is empty.

            // Load subcategories.
            $.ajax({
                // Look into how AJAX works youself ^^.
            });
        }
    },
    function()
    {
        //* What happens when the user's mouse leaves the target?

        // Hide the subcategories.
        $(this).find('div.subcategories').hide();
    });
});

Hope this helps! The jQuery AJAX documentation can be found

minitauros 151 Junior Poster Featured Poster

You can either create a JOIN in your original query, or execute a subquery for each subcategory. In the first case you'd have to use PHP to detect the start of a new section.

With a JOIN:

<?php
$q = 'SELECT tbl_categories.cat_id,
        tbl_categories.cat_name,
        tbl_subcategories.subcat_id,
        tbl_subcategories.subcat_name,
    FROM tbl_subcategories
    JOIN tbl_categories ON tbl_subcategories.cat_id = tbl_categories.cat_id
    ORDER BY tbl_categories.cat_id DESC';
$rq = mysql_query($q);

while($fetch = mysql_fetch_assoc($rq))
{
    $current_category = $fetch['cat_id'];

    if($current_category != $old_category)
    {
        // We've arrived at a new category.

        // << Do some stuff >>
    }

    // Remember the last category we've used.
    $old_category = $current_category;
}

Without a JOIN (with subqueries):

<?php
// Retrieve categories.
$q = 'SELECT tbl_categories.cat_id,
        tbl_categories.cat_name
    FROM tbl_categories
    ORDER BY tbl_categories.cat_id DESC';
$rq = mysql_query($q);

while($fetch = mysql_fetch_assoc($rq))
{
    //* Looping through categories.

    // Retrieve subcategories.
    $q2 = 'SELECT tbl_subcategories.subcat_id,
            tbl_subcategories.subcat_name
        FROM tbl_subcategories
        WHERE tbl_subcategories.cat_id = "' . $fetch['cat_id'] . '"
        ORDER BY tbl_subcategories.subcat_id DESC';
    $rq2 = mysql_query($q);

    while($fetch2 = mysql_fetch_assoc($rq2))
    {
        //* Looping through subcategories

        // << Do some stuff >>
    }
}
minitauros 151 Junior Poster Featured Poster

Oh by the way, it doesn't matter how many spaces you put between the dots, a tip for both of you then ^^. Whatever you find most comfortable to read!

minitauros 151 Junior Poster Featured Poster

Just a thought here: why don't you just use one field that you name "tags" (in your database). You can insert a comma separated list of tags into that field. When you retrieve it, you can explode it on the comma to create an array with tags. In that case you also don't have to check 5 separate fields for tags, you can suffice by asking your database to return a value "WHERE tags LIKE '%...%'".

For the rest, what is that semicolon (;) doing at the end of your SELECT query?

And for these error:

Warning: implode() [function.implode]: Invalid arguments passed on line 41
Notice: Insert failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' on line 43

Could you show us what's on line 41 and 43? :)

minitauros 151 Junior Poster Featured Poster

Yea that sounds interesting :o.

minitauros 151 Junior Poster Featured Poster

Well that's one nice explanation :)! What I would do is something like this:

<?php
// Get all your sections.
$q = 'SELECT section_id,
        section_name,
        topics_limit
    FROM sections
    ORDER BY section_id DESC';
$rq = mysql_query($q);

while($fetch = mysql_fetch_assoc($rq))
{
    // Looping through sections.

    // Retrieve topics for this section.

    $q2 = 'SELECT topic_id
            topic_name
        FROM topics
        WHERE section_id = "' . $fetch['section_id'] . '"
        ORDER BY topic_id DESC
        LIMIT ' . $fetch['topics_limit'];
    $rq2 = mysql_query($q2);

    while($fetch2 = mysql_fetch_assoc($rq2))
    {
        // Looping through topics.

    }
}
minitauros 151 Junior Poster Featured Poster

What is says is that $media->group->thumbnail[0] is not an object. Maybe you could find out why? I haven't worked with simplexml for a while, but maybe it doesn't give all the properties it contains the possibility to use the attributes() function? Just some thoughts ^^.

minitauros 151 Junior Poster Featured Poster

Yes or that, of course :). I was thinking of that but I thought hmm yeah but what if you're retrieving a million rows per section, then sorting it in PHP might be a bit slower than executing a couple of queries with a limit ^^. So depends on your situation!

minitauros 151 Junior Poster Featured Poster

Pfew I don't think you can do that in just one query. Not sure though, please correct me if I'm wrong. What I would do if you want to have a different limit for each section, is just execute multiple queries, one for each section, to exactly fit your needs.

minitauros 151 Junior Poster Featured Poster

So.. are you asking how you can get rid of your error on line 7 of "book here1.php"? If yes, could you share with us what's on line 7 of that file? If no, could you please (re)phrase your question?

minitauros 151 Junior Poster Featured Poster

That is completely true ^^. I didn't mean to say that your code is wrong in any way, just wanted to explain the topic starter some stuff about regular expressions, so that he could pick the one that suits him best.

minitauros 151 Junior Poster Featured Poster

So what exactly is it that you're asking us? :)

minitauros 151 Junior Poster Featured Poster

About your regex:
You are checking only the first letter of your input string :).

[A-Za-z0-9] checks one characters
[A-Za-z0-9]+ checks 1 - infinity characters (until one is found that does not match), which means that at least one MUST match
[A-Za-z0-9]* checks 0 - infinity characters, which means no characters MUST match
[A-Za-z0-9]*? checks 0 - infinity characters (until one is found that does not match (that's what the questionmark does)), which also means that no characters MUST match

In the example that Airshow is giving:

/^(_|[A-Za-z0-9])*$/
What this regex means is: May be empty (because of the asterix (*)) or, if it is not empty, it must have only underscores and or letters and numbers.

^ defines the start of a string
$ defines the end of a string
(_|[A-Za-z0-9]) means either underscore or letters or numbers

What should work:
/^[a-z0-9]+$/i
What this regex means is: Must start with a number or letter, must contain at least one character, may contain only numbers and letters, is a case insensitive check (that's what the "i" means after the last backslash).

minitauros 151 Junior Poster Featured Poster

Well since you must retrieve all sections and topics anyway, you could still use the query in my last example and then use PHP to sort the results. For example:

<?php
$q = 'SELECT topics.topic_name,
        sections.section_name
    FROM topics
    JOIN sections ON topics.section_id = sections.section_id
    ORDER BY sections.section_id DESC';

// Execute the query the way you want to execute it.

while(// Loop through the results in your own way.)
{
    // Get the current record's section name.
    $section_name = $results['section_name'];

    // If the current record's section name differs from the previous,
    // it means a new section has started.
    if($section_name != $old_section_name)
    {
        // A new section has started. Do anything you want to do if it has.
    }

    // Remember the last section name that we've used.
    $old_section_name = $results['section_name'];

    // Display info.
}
minitauros 151 Junior Poster Featured Poster

Well I don't think it is necessary to have sec_id and topic_id be the same ID. What you can do is:

Table 1 (sections):
id | section_name

Table 2 (topics):
id | section_id | topic_name

Then when a user opens for example the section with the ID 1, you could do the following:

SELECT topic_name FROM topics WHERE section_id = [the given section ID]

Is that about what you are looking for?

If you would want to select all sections with their topics at once, you could (for example) do this:

SELECT topics.topic_name,
    sections.section_name
FROM topics
JOIN sections ON topics.section_id = sections.section_id
ORDER BY sections.section_id DESC
minitauros 151 Junior Poster Featured Poster

Just a usability note: "Your form submission has an error." is kind of an unclear error message. Do you really want the user to read such a thing? He might get confused ;).

minitauros 151 Junior Poster Featured Poster

What you can do is redirect everything to index.php, then in index.php you read your URI by using $_SERVER['REQUEST_URI'], and then parsing that info. E.g. if REQUEST_URI returns "page/a-nice-html-page/" you could explode that data on the "/", scan that array and take the required actions in index.php. E.g. if $return[0] = page and $return[1] = a-nice-html-page you can include a page file called a-nice-html-page.

minitauros 151 Junior Poster Featured Poster

Great thanks! :)

minitauros 151 Junior Poster Featured Poster

So is this an informative article or a question? :) If it's the first, thanks! And if it's the second, what's the question? ;)

minitauros 151 Junior Poster Featured Poster

True that! You'll probably wanna use AJAX, then :).

minitauros 151 Junior Poster Featured Poster

No I mean his form's target is _blank, which means a new window will open and the original window will stay to exist to execute another form submission. At least, that MIGHT be so, I've never tested it, but that's why I came up with the idea :p.

minitauros 151 Junior Poster Featured Poster

Yea but you're being sent to a new tab, right? So the original tab will remain to exist :).

minitauros 151 Junior Poster Featured Poster

No idea if it works, but maybe this is an idea?

function buttonOne()
{
    document.Form1.target = "_blank";

    // Submit data to first domain.
    document.Form1.action = "http:/my domain 1/action.php"
    document.Form1.submit();

    // Submit data to second domain.
    document.Form1.action = "http:/my domain 2/action.php"
    document.Form1.submit();

    return true; 
}
minitauros 151 Junior Poster Featured Poster

If you want to place <b> tags around every element in your array, you can use the following:

<?php
function makeBold(&$input)
{
    // The & sign is used to make live changes to the input value.
    $input = '<b>' . $input . '</b>';
}

// Execute the function for every element in every dimension of your array.
array_walk_recursive($your_array, 'makeBold');
minitauros 151 Junior Poster Featured Poster

For the first problem:

<?php
$q = 'SELECT anything
    FROM copyright
    WHERE copyr_md5 = "' . mysql_real_escape_string($md5check) . '"
    LIMIT 1';
$rq = mysql_query($q);
$fetch = mysql_fetch_assoc($rq);

if($fetch)
{
    // A record that matches $md5check has been found.
}
?>

For the second problem:

<?php
$q = 'SELECT field1,
    field2,
    field3
    FROM table
    WHERE md5checksum = "' . mysql_real_escape_string($md5check) . '"
    LIMIT 1';
$rq = mysql_query($q);
$fetch = mysql_fetch_assoc($rq);

if($fetch)
{
    // A record that matches $md5check has been found.
    $field1 = $fetch['field1']; // etc.
}
minitauros 151 Junior Poster Featured Poster

Well you could write that a bit cleaner :). For example I'd use a switch (but maybe you should think about putting all this in a database).

<?php
$diagnostics = $_POST['diagnostics'];
$room = $_POST['room'];

if($diagnostics == 'Plomb CREP')
{
    switch($room)
    {
        case '95':
            $price = 120;
            break;
        case '100':
            $price = 140;
            break;

        // Etc.
    }

    echo 'Price for Plomb CREP: ' . $price . '<br/>';
}
else
    echo 'Diagnostics price: ' . $pieces . '<br/>';
?> 

But I'm still not 100% sure what you're trying to achieve. Maybe I can help you better if you'd be a little bit more specific :).

minitauros 151 Junior Poster Featured Poster

I once ran into Felipe Ribeiro's spelling corrector class. It can do spelling suggestions like "did you mean... ?". I think it can be useful in this case. You can find it here. It's a pretty nifty piece of work :).

minitauros 151 Junior Poster Featured Poster

What happens when you include a file, is that the contents of the file that is being included are loaded on the place where your include function is executed.

So, for example, when you have code like:

<html>
include 'header.php';

... blablabla ...
</html>

And header.php looks like this:

<head>
... blablabla ...
</head>

the output to your browser will be as follows:

<html>
<head>
... blablabla ...
</head>

... blablabla ...
</html>

You should double check if the link to your CSS file is working :). You don't need separate CSS files.